-
Notifications
You must be signed in to change notification settings - Fork 583
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
Fix resource leaks #591
Fix resource leaks #591
Conversation
This PR still needs to add a fix for |
On Windows, cached connection can keep file handler then it causes resource leak. We have no motivation to use cached connection so we disable cache by default. This commit is cherry-pick from roberthubert@7c47138
public static Project readXML(File f) throws IOException, SAXException { | ||
InputStream in = new BufferedInputStream(new FileInputStream(f)); | ||
public static Project readXML(File f) throws IOException, SAXException { | ||
@SuppressWarnings("resource") // will be closed by caller | ||
Project project = new Project(); |
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.
} | ||
|
||
@CheckReturnValue | ||
private Project createProject(Path[] files) { | ||
final Project project = new Project(); |
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.
Other issues targeted for 3.1.3, like #593/#602 were already fixed. If I understood it right, it seems that 3.1.3 was not yet released because it should contain the fix for this issue. However, #593/#602 is a blocker for me, so I'm really needing a new release ASAP. Then, I would like to know if this issue is in a state to be fixed and merged very soon or not. If not, I suggest to defer it to 3.1.4 and release 3.1.3 with what we already have. |
CHANGELOG.md
Outdated
@@ -15,6 +15,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. | |||
* Handle annotation on `package-info.class` properly ([#592](https://github.com/spotbugs/spotbugs/issues/592)) | |||
* Update asm to 6.1.1 to support Java 10 | |||
* Update Apache BCEL to 6.2 to support Java 9 package & module reference | |||
* Close source file after analysis ([#591](https://github.com/spotbugs/spotbugs/issues/591)) |
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.
I'll move this to Unreleased
part
@iloveeclipse please check and review:
Note that we can ignore these two SonarQube warnings; method caller should be responsible to close resources, not these methods themselves. |
If I remember right, |
OK then I will stop closing project in |
@@ -137,7 +138,7 @@ void storeAdjustment(String key, String value) { | |||
if (u == null) { | |||
return; | |||
} | |||
BufferedReader in = UTF8.bufferedReader(u.openStream()); | |||
BufferedReader in = UTF8.bufferedReader(IO.openNonCachedStream(u)); | |||
try { | |||
while (true) { |
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.
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.WillClose; | ||
import javax.annotation.WillNotClose; | ||
|
||
import edu.umd.cs.findbugs.annotations.CheckReturnValue; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.util.Util; | ||
|
||
public class IO { |
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.
@@ -267,8 +267,8 @@ private static void finishLazyInitialization() { | |||
System.err.println(msg); |
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.
@@ -1623,8 +1614,6 @@ public static Summary validate(File file) throws IllegalArgumentException { | |||
throw new IllegalArgumentException(e); | |||
} catch (IOException e) { |
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.
if (!bugReporter.getQueuedErrors().isEmpty()) { | ||
AssertionError assertionError = new AssertionError( | ||
"Analysis failed with exception. Check stderr for detail."); | ||
bugReporter.getQueuedErrors().stream().map(error -> error.getCause()) |
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.
final Project project = new Project(); | ||
project.setProjectName(getClass().getSimpleName()); | ||
engine.setProject(project); | ||
|
||
if (PLUGIN_JAR != null) { | ||
try { | ||
String pluginId = Plugin.addCustomPlugin(PLUGIN_JAR.toURI()).getPluginId(); |
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.
@@ -648,17 +648,14 @@ boolean processZipEntries(File f, ZipElementHandler handler) { | |||
System.out.println("empty zip file: '" + f + "'"); |
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.
SonarQube analysis reported 254 issues Watch the comments in this conversation to review them. Top 10 extra issuesNote: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:
|
@iloveeclipse PR has succeeded. Please check. I think all the warning by spotbugs can be ignored, since they're for existing code, not the newly added one. Please use 'squash and merge' to merge this PR, it seems that recently GitHub isn't so wise to handle conflict. |
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.
LGTM
Current implementation does not close
SourceFinder
even after analysis.This PR also applies try-with-resources to handle zip files.
@iloveeclipse I'm not sure about the difference between
FindBugs2#dispose()
andFindBugs2#clearCache()
, could you review? At least, can we destructproject
instance byclearCaches()
or not?