-
Notifications
You must be signed in to change notification settings - Fork 143
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 |
elharo
left a comment
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? |
...esolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
Show resolved
Hide resolved
...esolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
Show resolved
Hide resolved
...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.
yes |
|
Hey @elharo @olamy @slachiewicz Could you please review? |
| * @return the temporary directory | ||
| * @throws IOException if an I/O error occurs | ||
| * @deprecated use {@code @TempDir} (JUnit 5) or {@code TemporaryFolder} (JUnit 4) instead | ||
| * @deprecated use {@code @TempDir} (JUnit 5) or {@code TemporaryFolder} (JUnit |
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 line shouldn't have changed in this PR
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.
Sorry, I will fix it. Actually I was getting some syntax formatting issue, so used LLM to fix it, forgot to remove this line.
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.
Removed white space from two TestFileProcessor and TestFileUtil. Please check now.
|
hey @olamy please review |
|
Hey @olamy / @slachiewicz , could you please review |
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: