Plug an `InputStream` resource leak

This commit is contained in:
Ben Liblit 2017-08-17 11:57:17 -05:00 committed by Manu Sridharan
parent 5751c949e8
commit 4378fbbc12
1 changed files with 22 additions and 21 deletions

View File

@ -134,28 +134,29 @@ public final class WalaProperties {
if (fileName == null) {
throw new IllegalArgumentException("null fileName");
}
final InputStream propertyStream = loader.getResourceAsStream(fileName);
if (propertyStream == null) {
// create default properties
Properties defprop = new Properties();
defprop.setProperty(OUTPUT_DIR, "./out");
defprop.setProperty(INPUT_DIR, "./in");
defprop.setProperty(ECLIPSE_PLUGINS_DIR, "./plugins");
defprop.setProperty(WALA_REPORT, "./wala_report.txt");
defprop.setProperty(J2EE_DIR, "./j2ee");
final String j2selib = guessJavaLib();
defprop.setProperty(J2SE_DIR, j2selib);
return defprop;
try (final InputStream propertyStream = loader.getResourceAsStream(fileName)) {
if (propertyStream == null) {
// create default properties
Properties defprop = new Properties();
defprop.setProperty(OUTPUT_DIR, "./out");
defprop.setProperty(INPUT_DIR, "./in");
defprop.setProperty(ECLIPSE_PLUGINS_DIR, "./plugins");
defprop.setProperty(WALA_REPORT, "./wala_report.txt");
defprop.setProperty(J2EE_DIR, "./j2ee");
final String j2selib = guessJavaLib();
defprop.setProperty(J2SE_DIR, j2selib);
return defprop;
}
Properties result = new Properties();
result.load(propertyStream);
if (!result.containsKey(J2SE_DIR)) {
final String j2selib = guessJavaLib();
result.setProperty(J2SE_DIR, j2selib);
}
return result;
}
Properties result = new Properties();
result.load(propertyStream);
if (!result.containsKey(J2SE_DIR)) {
final String j2selib = guessJavaLib();
result.setProperty(J2SE_DIR, j2selib);
}
return result;
}
public static String guessJavaLib() throws IOException {