Skip to content

Comments

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

Open
DocJlm wants to merge 2 commits intoapache:3.3from
DocJlm:fix/resource-leaks-in-config-utils
Open

[#16098] Fix resource leaks and improve code quality in ConfigUtils#16097
DocJlm wants to merge 2 commits intoapache:3.3from
DocJlm:fix/resource-leaks-in-config-utils

Conversation

@DocJlm
Copy link

@DocJlm DocJlm commented Feb 21, 2026

What is the purpose of the change?

Fix resource leaks and improve code quality in ConfigUtils (dubbo-common module). Fixes #16098.

  • Refactor loadProperties() to use try-with-resources for FileInputStream, eliminating manual close() calls and potential resource leaks
  • Refactor multi-file loading loop to use try-with-resources for InputStream from URL, removing empty catch blocks
  • Fix resource leak in loadMigrationRule() where InputStream from URL was never closed after reading

The most critical fix is in loadMigrationRule() where an InputStream opened via url.openStream() is never closed, which can lead to file handle leaks in long-running applications.

Checklist

  • Make sure there is a GitHub issue filed for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • This PR only changes resource management patterns without altering logic. Existing tests cover the functionality, no new unit tests needed.
  • GitHub Actions should pass — no logic changes, only resource management improvements.

- Replace StringBuffer with StringBuilder in replaceProperty() method
  for better performance (no thread-safety needed for local variable)
- Refactor loadProperties() to use try-with-resources for FileInputStream,
  eliminating manual close() calls and potential resource leaks
- Refactor multi-file loading loop to use try-with-resources for
  InputStream from URL, removing empty catch blocks
- Fix resource leak in loadMigrationRule() where InputStream from URL
  was never closed after reading
@DocJlm DocJlm changed the title fix: fix resource leaks and improve code quality in ConfigUtils [#16098] Fix resource leaks and improve code quality in ConfigUtils Feb 21, 2026
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.80%. Comparing base (06334a5) to head (b96c4f0).

Files with missing lines Patch % Lines
...ava/org/apache/dubbo/common/utils/ConfigUtils.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16097      +/-   ##
============================================
- Coverage     60.80%   60.80%   -0.01%     
- Complexity    11750    11753       +3     
============================================
  Files          1953     1953              
  Lines         89121    89118       -3     
  Branches      13443    13444       +1     
============================================
- Hits          54192    54189       -3     
+ Misses        29369    29367       -2     
- Partials       5560     5562       +2     
Flag Coverage Δ
integration-tests-java21 32.12% <0.00%> (-0.06%) ⬇️
integration-tests-java8 32.24% <0.00%> (-0.02%) ⬇️
samples-tests-java21 32.14% <0.00%> (-0.04%) ⬇️
samples-tests-java8 29.74% <0.00%> (-0.01%) ⬇️
unit-tests-java11 59.06% <88.88%> (-0.01%) ⬇️
unit-tests-java17 58.54% <88.88%> (-0.03%) ⬇️
unit-tests-java21 58.57% <88.88%> (+0.01%) ⬆️
unit-tests-java25 58.50% <88.88%> (-0.01%) ⬇️
unit-tests-java8 59.06% <88.88%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@LI123456mo
Copy link
Contributor

Hi @DocJlm , I think the code is already implementing the "StringBuffer"?

@DocJlm
Copy link
Author

DocJlm commented Feb 23, 2026

Hi @DocJlm , I think the code is already implementing the "StringBuffer"?

Hi @LI123456mo, yes, you're right. I initially changed StringBuffer to StringBuilder in replaceProperty(), but the CI build failed because Matcher.appendReplacement() and Matcher.appendTail() only accept StringBuffer in Java 8 (the StringBuilder overload was added in Java 9).Since Dubbo needs to maintain Java 8 compatibility, I reverted that change. The remaining changes in this PR focus on fixing resource leaks using try-with-resources.

@LI123456mo
Copy link
Contributor

Hi @DocJlm , I think the code is already implementing the "StringBuffer"?

Hi @LI123456mo, yes, you're right. I initially changed StringBuffer to StringBuilder in replaceProperty(), but the CI build failed because Matcher.appendReplacement() and Matcher.appendTail() only accept StringBuffer in Java 8 (the StringBuilder overload was added in Java 9).Since Dubbo needs to maintain Java 8 compatibility, I reverted that change. The remaining changes in this PR focus on fixing resource leaks using try-with-resources.

If it is java 8 you are right to implement "StringBuffer"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants