-
Notifications
You must be signed in to change notification settings - Fork 139
Refactor resource management to use try-with-resources for better readability (Issue: #1521) #1623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…dability and automatic resource closing
@cstamas please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Test failures might be related:
|
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? |
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.java
write(File, String)
,write(File, InputStream)
, andcopy(File, File, ProgressListener)
methodsmaven-resolver-test-util/TestFileUtils.java
copyFile()
,readBytes()
,writeBytes()
,readProps()
, andwriteProps()
methodsmaven-resolver-test-http/HttpServer.java
maven-resolver-test-util/DependencyGraphParser.java
parse(URL)
methodmaven-resolver-test-util/IniArtifactDataReader.java
Benefits
✅ 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: