Skip to content

Fix UnsupportedOperationException in DubboDefaultPropertiesEnvironmentPostProcessor.addOrReplace on immutable property source (#16268)#16313

Open
wsyjh8 wants to merge 1 commit into
apache:3.3from
wsyjh8:fix/16268-immutable-default-properties
Open

Fix UnsupportedOperationException in DubboDefaultPropertiesEnvironmentPostProcessor.addOrReplace on immutable property source (#16268)#16313
wsyjh8 wants to merge 1 commit into
apache:3.3from
wsyjh8:fix/16268-immutable-default-properties

Conversation

@wsyjh8

@wsyjh8 wsyjh8 commented Jun 6, 2026

Copy link
Copy Markdown

What is the purpose of the change?

GitHub_issue: Fixes #16268

This pull request fixes the UnsupportedOperationException thrown by DubboDefaultPropertiesEnvironmentPostProcessor#addOrReplace when a defaultProperties source is already present and backed by an immutable map.

addOrReplace merged Dubbo's defaults by mutating the existing source's backing map in place via target.getSource().put(...). But MapPropertySource.getSource() returns the map the source was constructed with, which Spring does not guarantee is mutable. Since this post-processor runs at LOWEST_PRECEDENCE, another EnvironmentPostProcessor (e.g. Nacos / Spring Cloud bootstrap) may already have registered defaultProperties backed by an immutable map such as Guava ImmutableMap, so the put throws:

java.lang.UnsupportedOperationException
    at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:814)
    at org.apache.dubbo.spring.boot.env.DubboDefaultPropertiesEnvironmentPostProcessor.addOrReplace(DubboDefaultPropertiesEnvironmentPostProcessor.java:134)

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 via MutablePropertySources.replace(...) — the same approach as Spring Boot's own DefaultPropertiesPropertySource#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-backed defaultProperties no 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 test

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure GitHub actions can pass.

@wsyjh8 wsyjh8 force-pushed the fix/16268-immutable-default-properties branch from 38011f6 to 3e65d53 Compare June 6, 2026 23:30
@codecov-commenter

codecov-commenter commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.79%. Comparing base (990c513) to head (3e65d53).

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              
Flag Coverage Δ
integration-tests-java21 32.17% <0.00%> (+0.04%) ⬆️
integration-tests-java8 32.28% <0.00%> (+0.03%) ⬆️
samples-tests-java21 32.19% <0.00%> (+0.01%) ⬆️
samples-tests-java8 29.86% <0.00%> (+0.02%) ⬆️
unit-tests-java11 59.02% <100.00%> (+<0.01%) ⬆️
unit-tests-java17 58.53% <100.00%> (+0.03%) ⬆️
unit-tests-java21 58.50% <100.00%> (+<0.01%) ⬆️
unit-tests-java25 58.46% <100.00%> (-0.05%) ⬇️
unit-tests-java8 59.05% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@oneby-wang

Copy link
Copy Markdown

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.

@zrlw zrlw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EarthChen EarthChen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] UnsupportedOperationException occurred at DubboDefaultPropertiesEnvironmentPostProcessor#addOrReplace

6 participants