Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1797 - JEP 238 - Multi-Release JAR files break bytecode scanning. #1951

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to catch any Exception?
What if the jar file itself has entries that can be iterated, but not read?
Wouldn't that result in a MultiException containing an entry for each and every entry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets deal with this if it becomes a problem. Too complicated to work out now.

{
me.add(new RuntimeException("Error scanning entry " + e.getName() + " from jar " + jarResource, ex));
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception opening the JarFile isn't caught / added to the MultiException. (eg: a bad jar file)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, the method itself will pass a JarFile error out properly, no need for the MultiException route.

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