wsyjh8 commented on issue #16268:
URL: https://github.com/apache/dubbo/issues/16268#issuecomment-4640691297
@zrlw you're right that the failure comes from an immutable map being
registered as the
`defaultProperties` source. I'd argue the root cause is on Dubbo's side,
though.
`DubboDefaultPropertiesEnvironmentPostProcessor#addOrReplace` merges Dubbo's
defaults by
mutating the existing source's backing map in place
(`target.getSource().put(...)`, line 134).
`MapPropertySource#getSource()` returns the map the source was built with,
and Spring does not
guarantee it is mutable — so when an earlier `EnvironmentPostProcessor`
(Nacos / Spring Cloud
bootstrap, here on Spring Boot 3.2.1) has already registered a
`defaultProperties` source
backed by an immutable map, the `put` throws. Spring Boot's own
`DefaultPropertiesPropertySource#addOrMerge` (since 2.4.4) avoids exactly
this by copying into
a new map and calling `MutablePropertySources#replace` instead of mutating
in place.
Self-contained reproduction — no Nacos / Kubernetes needed:
```java
@Test
void reproduce() {
MockEnvironment environment = new MockEnvironment();
environment.getPropertySources().addLast(new MapPropertySource(
"defaultProperties", Collections.unmodifiableMap(new
HashMap<>())));
new DubboDefaultPropertiesEnvironmentPostProcessor()
.postProcessEnvironment(environment, new SpringApplication());
}
// -> java.lang.UnsupportedOperationException at ...addOrReplace:134
```
I've opened a PR that aligns `addOrReplace` with Spring Boot's
copy-and-`replace` approach
(while preserving Dubbo's "defaults don't override existing keys"
semantics), with this case as
a regression test. Happy to adjust the approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]