提交 4ac0604c 编写于 作者: A andrew

8003120: ResourceManager.getApplicationResources() does not close InputStreams

Summary: Add finally blocks to close the InputStream instances
Reviewed-by: lancea
上级 f6e03a56
...@@ -542,9 +542,15 @@ public final class ResourceManager { ...@@ -542,9 +542,15 @@ public final class ResourceManager {
try { try {
NamingEnumeration<InputStream> resources = NamingEnumeration<InputStream> resources =
helper.getResources(cl, APP_RESOURCE_FILE_NAME); helper.getResources(cl, APP_RESOURCE_FILE_NAME);
try {
while (resources.hasMore()) { while (resources.hasMore()) {
Properties props = new Properties(); Properties props = new Properties();
props.load(resources.next()); InputStream istream = resources.next();
try {
props.load(istream);
} finally {
istream.close();
}
if (result == null) { if (result == null) {
result = props; result = props;
...@@ -552,11 +558,18 @@ public final class ResourceManager { ...@@ -552,11 +558,18 @@ public final class ResourceManager {
mergeTables(result, props); mergeTables(result, props);
} }
} }
} finally {
while (resources.hasMore()) {
InputStream istream = (InputStream)resources.next();
istream.close();
}
}
// Merge in properties from file in <java.home>/lib. // Merge in properties from file in <java.home>/lib.
InputStream istream = InputStream istream =
helper.getJavaHomeLibStream(JRELIB_PROPERTY_FILE_NAME); helper.getJavaHomeLibStream(JRELIB_PROPERTY_FILE_NAME);
if (istream != null) { if (istream != null) {
try {
Properties props = new Properties(); Properties props = new Properties();
props.load(istream); props.load(istream);
...@@ -565,6 +578,9 @@ public final class ResourceManager { ...@@ -565,6 +578,9 @@ public final class ResourceManager {
} else { } else {
mergeTables(result, props); mergeTables(result, props);
} }
} finally {
istream.close();
}
} }
} catch (IOException e) { } catch (IOException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册