gnodet commented on code in PR #2222:
URL: https://github.com/apache/maven-resolver/pull/2222#discussion_r4793086123


##########
maven-resolver-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java:
##########
@@ -158,33 +157,24 @@ public List<DependencyNode> parseMultiResource(String 
resource) throws IOExcepti
             throw new IOException("Could not find classpath resource " + 
prefix + resource);

Review Comment:
   **Pre-existing (not from this change, not blocking):**
   
   Resource leak risk with nested resource constructors in try-with-resources. 
Both parseMultiResource and parse(URL resource) use nested constructors: new 
BufferedReader(new InputStreamReader(res.openStream(), ...)). If openStream() 
succeeds but a subsequent constructor throws, the InputStream leaks because it 
was never assigned to the try-with-resources variable.
   
   **Failure scenario:** res.openStream() returns InputStream, then new 
InputStreamReader() or new BufferedReader() throws OutOfMemoryError → 
InputStream leaks because it wasn't assigned to a variable that 
try-with-resources can close.
   
   **Fix:** Use separate try-with-resources declarations:
   ```java
   try (InputStream is = res.openStream();
        InputStreamReader isr = new InputStreamReader(is, 
StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isr)) {
       return parse(br);
   }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to