Skip to content

Commit c46398c

Browse files
committed
Merge branch 'matthieu-vergne-fix/jar_resource_leak'
2 parents bd61ce5 + a90993c commit c46398c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/main/java/gr/gousiosg/javacg/stat/JCallGraph.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,26 @@ public static void main(String[] args) {
5151
for (String arg : args) {
5252

5353
File f = new File(arg);
54-
54+
5555
if (!f.exists()) {
5656
System.err.println("Jar file " + arg + " does not exist");
5757
}
58-
59-
JarFile jar = new JarFile(f);
60-
61-
Enumeration<JarEntry> entries = jar.entries();
62-
while (entries.hasMoreElements()) {
63-
JarEntry entry = entries.nextElement();
64-
if (entry.isDirectory())
65-
continue;
6658

67-
if (!entry.getName().endsWith(".class"))
68-
continue;
59+
try (JarFile jar = new JarFile(f)) {
60+
Enumeration<JarEntry> entries = jar.entries();
61+
while (entries.hasMoreElements()) {
62+
JarEntry entry = entries.nextElement();
63+
if (entry.isDirectory())
64+
continue;
65+
66+
if (!entry.getName().endsWith(".class"))
67+
continue;
6968

70-
cp = new ClassParser(arg,entry.getName());
71-
ClassVisitor visitor = new ClassVisitor(cp.parse());
72-
visitor.start();
73-
}
69+
cp = new ClassParser(arg,entry.getName());
70+
ClassVisitor visitor = new ClassVisitor(cp.parse());
71+
visitor.start();
72+
}
73+
}
7474
}
7575
} catch (IOException e) {
7676
System.err.println("Error while processing jar: " + e.getMessage());

0 commit comments

Comments
 (0)