Bug 52738 - An incomplete fix for the resource leak bug in XMLResultAggregator.java
Summary: An incomplete fix for the resource leak bug in XMLResultAggregator.java
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.8.2
Hardware: All All
: P2 minor (vote)
Target Milestone: 1.9.0
Assignee: Ant Notifications List
Depends on:
Reported: 2012-02-23 04:13 UTC by lianggt08
Modified: 2012-02-27 21:37 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description lianggt08 2012-02-23 04:13:04 UTC
The fix revision 272185 was aimed to remove resource leak bugs on the OutputStream object "out" (created in line 232), the PrintWriter object "wri" (line 234) in the method "writeDOMTree"of the file 
"/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java" , but it is incomplete.

There are some problems: 
1. when "inReader" isn't created successfully but the temp OutputStreamWriter object is created successfully (at line 233), the temp OutputStreamWriter object will be leaked. 

The best way to close such resource objects is putting such close operations for all resource objects in the finaly block of a try-catch-finally structure and then putting all other code in a try block.

The problem still exists in the head revision (the temp OutputStreamWriter object created at 233 can be leaked).
Comment 1 Jesse Glick 2012-02-27 21:37:35 UTC
Committed revision 1294340. Only the FileOutputStream must be closed, since everything else is a wrapper.

By the way -source 7 provides the nicer try-with-resources idiom for this kind of thing.