Browse Source

Avoid leaks in AntAnalyzer

master
Gintas Grigelionis 6 years ago
parent
commit
aff7eefe14
1 changed files with 25 additions and 8 deletions
  1. +25
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java

+ 25
- 8
src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java View File

@@ -61,23 +61,24 @@ public class AntAnalyzer extends AbstractAnalyzer {
analyzedDeps.clear();
for (String classname : toAnalyze) {
dependencies.add(classname);
File container = null;
try {
File container = getClassContainer(classname);
if (container == null) {
continue;
}
container = getClassContainer(classname);
} catch (IOException ioe) {
// ignore
}
if (container != null) {
containers.add(container);

try (InputStream inStream = container.getName().endsWith(".class")
? Files.newInputStream(Paths.get(container.getPath()))
: new ZipFile(container.getPath()).getInputStream(new ZipEntry(
classname.replace('.', '/') + ".class"))) {
: getZipEntryStream(new ZipFile(container.getPath()), classname)) {
ClassFile classFile = new ClassFile();
classFile.read(inStream);
analyzedDeps.addAll(classFile.getClassRefs());
} catch (IOException ioe) {
// ignore
}
} catch (IOException ioe) {
// ignore
}
}

@@ -96,6 +97,22 @@ public class AntAnalyzer extends AbstractAnalyzer {
classes.addAll(dependencies);
}

private InputStream getZipEntryStream(ZipFile zipFile, String classname) throws IOException {
InputStream zipEntryStream = zipFile.getInputStream(new ZipEntry(
classname.replace('.', '/') + ".class"));
return new InputStream() {
@Override
public int read() throws IOException {
return zipEntryStream.read();
}
@Override
public void close() throws IOException {
zipEntryStream.close();
zipFile.close();
}
};
}

/**
* Indicate if this analyzer can determine dependent files.
*


Loading…
Cancel
Save