Refactor resource management to use try-with-resources for better readability (Issue: #1521)#1623
Open
dheeraj1010 wants to merge 5 commits intoapache:masterfrom
Open
Refactor resource management to use try-with-resources for better readability (Issue: #1521)#1623dheeraj1010 wants to merge 5 commits intoapache:masterfrom
dheeraj1010 wants to merge 5 commits intoapache:masterfrom
Conversation
…dability and automatic resource closing
Author
|
@cstamas please review |
elharo
requested changes
Oct 8, 2025
Contributor
elharo
left a comment
There was a problem hiding this comment.
This looks suspiciously like it was done with an LLM. Which one? Not necessarily a problem, but we should check if the Apache project has a policy on that.
Contributor
|
Test failures might be related: |
Contributor
slachiewicz
approved these changes
Oct 9, 2025
Member
|
Looks good, thanks! But IMO, deprecated things (TestFileProcessor, extending deprecated FileProcessor) may not need to be touched.... but is okay, as am afraid is used in other (test) code? |
olamy
reviewed
Oct 12, 2025
...esolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
Show resolved
Hide resolved
olamy
reviewed
Oct 12, 2025
...esolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
Show resolved
Hide resolved
olamy
requested changes
Oct 12, 2025
...esolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
Moved mkdirs() calls before try-with-resources block to ensure parent directories exist before FileOutputStream is created. This fixes the FileNotFoundException errors in EnhancedLocalRepositoryManagerTest.
Author
yes |
Author
|
Hey @elharo @olamy @slachiewicz Could you please review? |
slachiewicz
approved these changes
Jan 9, 2026
elharo
requested changes
Jan 9, 2026
maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java
Outdated
Show resolved
Hide resolved
elharo
approved these changes
Jan 10, 2026
Author
|
hey @olamy please review |
Author
|
Hey @olamy / @slachiewicz , could you please review |
slachiewicz
approved these changes
Jan 11, 2026
Author
|
Hey @olamy , could you please review? |
Author
|
Hey @olamy can you please review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR modernizes the Maven Resolver codebase by replacing manual resource management patterns with Java 7's try-with-resources statements. The changes eliminate verbose try-catch-finally blocks while improving code safety and readability.
Changes Made
Files Modified:
maven-resolver-test-util/TestFileProcessor.javawrite(File, String),write(File, InputStream), andcopy(File, File, ProgressListener)methodsmaven-resolver-test-util/TestFileUtils.javacopyFile(),readBytes(),writeBytes(),readProps(), andwriteProps()methodsmaven-resolver-test-http/HttpServer.javamaven-resolver-test-util/DependencyGraphParser.javaparse(URL)methodmaven-resolver-test-util/IniArtifactDataReader.javaBenefits
✅ Cleaner Code: Eliminates verbose try-catch-finally blocks
✅ Better Resource Management: Automatic resource cleanup with try-with-resources
✅ Reduced Error-Prone Code: Lower risk of resource leaks
✅ Modern Java Practices: Adopts Java 7+ features appropriately
✅ Improved Readability: More concise and easier to understand code
Before/After Example
Before: