Plug a `JarFile` resource leak

This commit is contained in:
Ben Liblit 2017-08-17 11:40:55 -05:00 committed by Manu Sridharan
parent e63de76139
commit eaf1c0af85
1 changed files with 4 additions and 5 deletions

View File

@ -392,11 +392,10 @@ public class AnalysisScope {
}
public String getJavaLibraryVersion() throws IllegalStateException {
JarFile rtJar = getRtJar();
if (rtJar == null) {
throw new IllegalStateException("cannot find runtime libraries");
}
try {
try (final JarFile rtJar = getRtJar()) {
if (rtJar == null) {
throw new IllegalStateException("cannot find runtime libraries");
}
Manifest man = rtJar.getManifest();
assert man != null : "runtime library has no manifest!";
String result = man.getMainAttributes().getValue("Specification-Version");