You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "DocJlm (via GitHub)" <gi...@apache.org> on 2026/02/21 08:21:29 UTC

[PR] fix: fix resource leaks and improve code quality in ConfigUtils [dubbo]

DocJlm opened a new pull request, #16097:
URL: https://github.com/apache/dubbo/pull/16097

   - 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
   
   ## What is the purpose of the change?
   
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] 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](https://github.com/apache/dubbo-samples) project.
   - [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md)
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] [#16098] Fix resource leaks and improve code quality in ConfigUtils [dubbo]

Posted by "RainYuY (via GitHub)" <gi...@apache.org>.
RainYuY merged PR #16097:
URL: https://github.com/apache/dubbo/pull/16097


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] [#16098] Fix resource leaks and improve code quality in ConfigUtils [dubbo]

Posted by "LI123456mo (via GitHub)" <gi...@apache.org>.
LI123456mo commented on PR #16097:
URL: https://github.com/apache/dubbo/pull/16097#issuecomment-3942178195

   > > 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"


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] [#16098] Fix resource leaks and improve code quality in ConfigUtils [dubbo]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #16097:
URL: https://github.com/apache/dubbo/pull/16097#issuecomment-3938600534

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/16097?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `0%` with `9 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 32.14%. Comparing base ([`06334a5`](https://app.codecov.io/gh/apache/dubbo/commit/06334a5407b63ec53dd26c739f14d810471444f5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`b96c4f0`](https://app.codecov.io/gh/apache/dubbo/commit/b96c4f0373650ee92a816f9162957519d3d2ee9a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/dubbo/pull/16097?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ava/org/apache/dubbo/common/utils/ConfigUtils.java](https://app.codecov.io/gh/apache/dubbo/pull/16097?src=pr&el=tree&filepath=dubbo-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fcommon%2Futils%2FConfigUtils.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vdXRpbHMvQ29uZmlnVXRpbHMuamF2YQ==) | 0.00% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16097?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (06334a5) and HEAD (b96c4f0). Click for more details.
   > 
   > <details><summary>HEAD has 8 uploads less than BASE</summary>
   >
   >| Flag | BASE (06334a5) | HEAD (b96c4f0) |
   >|------|------|------|
   >|samples-tests-java8|1|0|
   >|integration-tests-java21|1|0|
   >|integration-tests-java8|1|0|
   >|unit-tests-java8|1|0|
   >|unit-tests-java11|1|0|
   >|unit-tests-java25|1|0|
   >|unit-tests-java17|1|0|
   >|unit-tests-java21|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##                3.3   #16097       +/-   ##
   =============================================
   - Coverage     60.80%   32.14%   -28.67%     
   + Complexity    11750    10198     -1552     
   =============================================
     Files          1953     1952        -1     
     Lines         89121    89096       -25     
     Branches      13443    13360       -83     
   =============================================
   - Hits          54192    28640    -25552     
   - Misses        29369    56249    +26880     
   + Partials       5560     4207     -1353     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [integration-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [samples-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.14% <0.00%> (-0.04%)` | :arrow_down: |
   | [samples-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java11](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java17](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java25](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16097/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo/pull/16097?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] [#16098] Fix resource leaks and improve code quality in ConfigUtils [dubbo]

Posted by "LI123456mo (via GitHub)" <gi...@apache.org>.
LI123456mo commented on PR #16097:
URL: https://github.com/apache/dubbo/pull/16097#issuecomment-3941507692

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


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] [#16098] Fix resource leaks and improve code quality in ConfigUtils [dubbo]

Posted by "DocJlm (via GitHub)" <gi...@apache.org>.
DocJlm commented on PR #16097:
URL: https://github.com/apache/dubbo/pull/16097#issuecomment-3942083052

   > 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. 


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org