Skip to content

Commit

Permalink
Issue #1797 - JEP 238 - Multi-Release JAR files break bytecode scanning.
Browse files Browse the repository at this point in the history
Made MultiReleaseJarFile closeable and using try-with-resources in
AnnotationParser to avoid leaking file descriptors.

Made few code simplifications.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Nov 8, 2017
1 parent 7a6d7bd commit 0a971cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,18 +916,20 @@ protected void parseJar (Set<? extends Handler> handlers, Resource jarResource,
LOG.debug("Scanning jar {}", jarResource);

MultiException me = new MultiException();
MultiReleaseJarFile jarFile = new MultiReleaseJarFile(jarResource.getFile(),_javaPlatform,false);
jarFile.stream().forEach(e->
try (MultiReleaseJarFile jarFile = new MultiReleaseJarFile(jarResource.getFile(),_javaPlatform,false))
{
try
{
parseJarEntry(handlers, jarResource, e, resolver);
}
catch (Exception ex)
jarFile.stream().forEach(e->
{
me.add(new RuntimeException("Error scanning entry " + e.getName() + " from jar " + jarResource, ex));
}
});
try
{
parseJarEntry(handlers, jarResource, e, resolver);
}
catch (Exception ex)
{
me.add(new RuntimeException("Error scanning entry " + e.getName() + " from jar " + jarResource, ex));
}
});
}
me.ifExceptionThrow();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

package org.eclipse.jetty.util;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.jar.JarEntry;
Expand All @@ -33,7 +35,7 @@
/**
* <p>Utility class to handle a Multi Release Jar file</p>
*/
public class MultiReleaseJarFile
public class MultiReleaseJarFile implements Closeable
{
private static final String META_INF_VERSIONS = "META-INF/versions/";

Expand Down Expand Up @@ -84,12 +86,10 @@ public MultiReleaseJarFile(File file, int javaPlatform, boolean includeDirectori
{
Map.Entry<String,VersionedJarEntry> e = i.next();
VersionedJarEntry entry = e.getValue();

if (entry.inner)
{
VersionedJarEntry outer = entry.outer==null?null:map.get(entry.outer);

if (entry.outer==null || outer==null || outer.version!= entry.version)
if (outer==null || outer.version!=entry.version)
i.remove();
}
}
Expand Down Expand Up @@ -130,6 +130,13 @@ public VersionedJarEntry getEntry(String name)
return entries.get(name);
}

@Override
public void close() throws IOException
{
if (jarFile!=null)
jarFile.close();
}

@Override
public String toString()
{
Expand Down Expand Up @@ -172,8 +179,8 @@ public class VersionedJarEntry
this.entry = entry;
this.name = name;
this.version = v;
this.inner = name.contains("$") && name.toLowerCase().endsWith(".class");
this.outer = inner ? name.substring(0, name.indexOf('$')) + name.substring(name.length() - 6, name.length()) : null;
this.inner = name.contains("$") && name.toLowerCase(Locale.ENGLISH).endsWith(".class");
this.outer = inner ? name.substring(0, name.indexOf('$')) + ".class" : null;
}

/**
Expand Down

0 comments on commit 0a971cb

Please sign in to comment.