Fix potential resource leaks

See gh-11624
This commit is contained in:
igor-suhorukov
2018-01-13 15:10:52 +03:00
committed by Stephane Nicoll
parent 0b22eb90b5
commit 5a4238acfc
4 changed files with 21 additions and 12 deletions

View File

@@ -215,16 +215,16 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
@Override
public void writeLoaderClasses(String loaderJarResourceName) throws IOException {
URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName);
JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()));
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
writeEntry(new JarArchiveEntry(entry),
new InputStreamEntryWriter(inputStream, false));
try (JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()))) {
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
writeEntry(new JarArchiveEntry(entry),
new InputStreamEntryWriter(inputStream, false));
}
}
}
inputStream.close();
}
/**