Fix UnsupportedOperationException in DubboDefaultPropertiesEnvironmentPostProcessor.addOrReplace on immutable property source (#16268)#16313
Open
wsyjh8 wants to merge 1 commit into
Conversation
5 tasks
…tPostProcessor on immutable defaultProperties (apache#16268)
38011f6 to
3e65d53
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16313 +/- ##
============================================
+ Coverage 60.77% 60.79% +0.01%
- Complexity 11763 11767 +4
============================================
Files 1953 1953
Lines 89203 89205 +2
Branches 13458 13458
============================================
+ Hits 54216 54234 +18
+ Misses 29414 29398 -16
Partials 5573 5573
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
v6z5tg2tzb-cyber
approved these changes
Jun 7, 2026
|
Hi, @wsyjh8, I'm also working on this issue. I noticed you've already submitted a PR, so I'm sharing my PR here as well for reference: oneby-wang#1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change?
GitHub_issue: Fixes #16268
This pull request fixes the
UnsupportedOperationExceptionthrown byDubboDefaultPropertiesEnvironmentPostProcessor#addOrReplacewhen adefaultPropertiessource is already present and backed by an immutable map.addOrReplacemerged Dubbo's defaults by mutating the existing source's backing map in place viatarget.getSource().put(...). ButMapPropertySource.getSource()returns the map the source was constructed with, which Spring does not guarantee is mutable. Since this post-processor runs atLOWEST_PRECEDENCE, anotherEnvironmentPostProcessor(e.g. Nacos / Spring Cloud bootstrap) may already have registereddefaultPropertiesbacked by an immutable map such as GuavaImmutableMap, so theputthrows:The fix copies the existing entries into a new mutable
HashMap, merges Dubbo's defaults only for keys not already present (unchanged precedence), and replaces the source in place viaMutablePropertySources.replace(...)— the same approach as Spring Boot's ownDefaultPropertiesPropertySource#addOrMerge. The mutable case behaves identically; the immutable case no longer throws. No public signature or behaviour change, and the Java 8 language level is preserved.Two regression tests were added in
DubboDefaultPropertiesEnvironmentPostProcessorTest: one asserts an immutable-backeddefaultPropertiesno longer throws, the other asserts an already-present key is still not overridden by Dubbo's default.Verification
git diff --check./mvnw -pl dubbo-spring-boot-project/dubbo-spring-boot -am -Dtest=DubboDefaultPropertiesEnvironmentPostProcessorTest -Dsurefire.failIfNoSpecifiedTests=false testChecklist