Skip to content

[Bug] Config merging mutates incoming parameters and rejects read-only maps #16535

Open

Description

@bajiaoshan

Pre-check

  • All content is in English.
  • Searched existing issues and open pull requests; no matching fix was found.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

3.3.7-SNAPSHOT, branch 3.3, commit 843b98b3a1c70134e965ab04efc2de668238e0b2.
Windows 11, Eclipse Temurin JDK 17.0.20.1, Maven 3.9.14.

Steps to reproduce this issue

Merging two application configurations with OVERRIDE_ALL or OVERRIDE_IF_ABSENT calls AbstractConfig.overrideWithConfig. The following isolates the same merge:

ApplicationConfig target = new ApplicationConfig("app");
target.setParameters(Collections.singletonMap("old-only", "old-value"));
ApplicationConfig incoming = new ApplicationConfig("app");
incoming.setParameters(Collections.singletonMap("new-only", "new-value"));

target.overrideWithConfig(incoming, true);

Use imports org.apache.dubbo.config.ApplicationConfig and java.util.Collections.

The merge fails with IllegalStateException caused by UnsupportedOperationException: oldMap.forEach(newMap::putIfAbsent) writes into the incoming, read-only map. Passing false fails at newMap.putAll(oldMap) instead.

With a mutable incoming map, the merge completes but adds old-only to that map. In OVERRIDE_IF_ABSENT, values for overlapping keys in the incoming configuration are also overwritten by the target's values.

What you expected to happen

The target should receive the merged parameters, respecting the selected mode's precedence. The incoming configuration and its caller-provided map should retain their original entries. Providing read-only parameters should not prevent the merge.

Anything else

Four parameterized regression cases reproduce both behaviors through ConfigManager.addConfig: two modes, each with mutable or unmodifiable incoming parameters. On the original code, two cases fail source-map assertions and two error with UnsupportedOperationException. Copying the incoming map before merging makes all four pass, while retaining the existing key precedence.

Are you willing to submit a pull request?

Yes. A minimal fix and regression tests are prepared.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions