fix(config): close resource streams - #48
Conversation
📝 WalkthroughWalkthroughThis PR fixes resource leaks in java-tron by converting manual stream handling to try-with-resources in configuration loading, version/commit metadata reading, zk-snark parameter loading, and plugin directory-walk utilities. Tests are updated to match. A differential review report documents the changes. ChangesResource leak remediation
Estimated code review effort: 2 (Simple) | ~15 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java`:
- Around line 60-66: Update the resourcePath construction in the
ZksnarkInitService initialization flow to always use "/" between "params" and
fileName for ClassLoader.getResourceAsStream. Keep File.separator unchanged for
the temporary filesystem path used by fileOut.
In `@JAVA_TRON_DIFFERENTIAL_REVIEW_2026-08-04.md`:
- Around line 109-110: Update the PR `#45` statement in the review document to
remove the claim that the analogous Files.walk() fixes were omitted, since those
fixes are already included in the reviewed scope. Preserve the statement about
missing tests, or rename the PR reference only if the line is intended to
describe a different pull request.
- Around line 95-100: Revise the coverage conclusion in the report to explicitly
state that the missing-resource branch throwing IllegalStateException remains
untested, while retaining the 94.12% metric and CI-threshold qualification. Do
not claim that existing tests provide complete coverage unless you add a focused
test for that branch.
- Around line 114-128: The audit result claims all remaining resource-leak
matches have been identified, but the listed search scope does not include NIO
factory methods like Files.newInputStream, Files.newBufferedReader, and
FileChannel.open that can also own file descriptors. Either expand the
bullet-point list of searched APIs to include these NIO factories if the audit
covered them, or reword the conclusion statement to explicitly scope the "all
remaining matches" claim to only the APIs listed in the search.
- Around line 63-65: Update the classpath resource lookup to build its name with
the literal forward slash in the parameter-loading logic, while retaining
File.separator only for filesystem paths. Revise the nearby
platform-compatibility wording to no longer claim the resource construction is
platform-specific.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8a143d35-cbb2-4dc9-a02b-2cbb21110236
📒 Files selected for processing (8)
JAVA_TRON_DIFFERENTIAL_REVIEW_2026-08-04.mdcommon/src/main/java/org/tron/core/config/Configuration.javaframework/src/main/java/org/tron/core/config/args/Args.javaframework/src/main/java/org/tron/core/zen/ZksnarkInitService.javaframework/src/test/java/org/tron/common/utils/FileUtilTest.javaframework/src/test/java/org/tron/core/services/http/BroadcastServletTest.javaframework/src/test/java/org/tron/core/services/http/solidity/GetTransactionByIdSolidityServletTest.javaplugins/src/main/java/common/org/tron/plugins/utils/FileUtils.java
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
911607c to
9bbf15f
Compare
What does this PR do?
Closes classpath resource streams used by configuration, Git metadata, and zk parameter loading. It also scopes analogous
Files.walk()streams in plugin utilities and affected tests, and handles missing zk parameter resources explicitly.Why are these changes required?
Unclosed classpath and NIO streams can retain file or directory handles until garbage collection, potentially causing resource exhaustion or platform-dependent failures during repeated operations.
This PR has been tested by:
Follow up
None
Extra details
The repository was scanned for analogous resource-management omissions. No new test methods or test classes were added.