Skip to content

[Bug] Fix resource leaks and improve code quality in ConfigUtils #16098

@DocJlm

Description

@DocJlm

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo 3.3.x, branch 3.3 (source code review)

Steps to reproduce this issue

  1. Open dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConfigUtils.java
  2. In replaceProperty() method (line 142): StringBuffer is used for a local variable, StringBuilder would be more appropriate
  3. In loadMigrationRule() method: InputStream opened via url.openStream() is never closed after readString() returns — this is a confirmed resource leak
  4. In loadProperties() multi-file loop: uses nested try-finally with empty catch blocks instead of try-with-resources

What you expected to happen

  1. Local variables should use StringBuilder instead of StringBuffer when thread-safety is not needed
  2. All InputStream resources should be properly closed using try-with-resources to prevent file handle leaks
  3. Empty catch blocks should be eliminated

Anything else

The most critical issue is in loadMigrationRule() where an InputStream opened via url.openStream() is never closed. In long-running applications this can lead to file descriptor exhaustion ("Too many open files" error).

I will submit a PR to fix all these issues.

Do you have a (mini) reproduction demo?

  • Yes, I have a minimal reproduction demo to help resolve this issue more effectively!

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for starters to contributetype/bugBugs to being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions