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

Change JarHell to operate on Path instead of URL #12109

Merged
merged 1 commit into from Jul 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 13 additions & 14 deletions core/src/main/java/org/elasticsearch/bootstrap/JarHell.java
Expand Up @@ -81,10 +81,10 @@ public static void checkJarHell(URL urls[]) throws Exception {
// a "list" at all. So just exclude any elements underneath the java home
String javaHome = System.getProperty("java.home");
logger.debug("java.home: {}", javaHome);
final Map<String,URL> clazzes = new HashMap<>(32768);
Set<String> seenJars = new HashSet<>();
final Map<String,Path> clazzes = new HashMap<>(32768);
Set<Path> seenJars = new HashSet<>();
for (final URL url : urls) {
String path = PathUtils.get(url.toURI()).toString();
final Path path = PathUtils.get(url.toURI());
// exclude system resources
if (path.startsWith(javaHome)) {
logger.debug("excluding system resource: {}", path);
Expand All @@ -96,7 +96,7 @@ public static void checkJarHell(URL urls[]) throws Exception {
continue; // we can't fail because of sheistiness with joda-time
}
logger.debug("examining jar: {}", path);
try (JarFile file = new JarFile(path)) {
try (JarFile file = new JarFile(path.toString())) {
Manifest manifest = file.getManifest();
if (manifest != null) {
// inspect Manifest: give a nice error if jar requires a newer java version
Expand Down Expand Up @@ -124,7 +124,7 @@ public static void checkJarHell(URL urls[]) throws Exception {
if (entry.endsWith(".class")) {
// for jar format, the separator is defined as /
entry = entry.replace('/', '.').substring(0, entry.length() - 6);
checkClass(clazzes, entry, url);
checkClass(clazzes, entry, path);
}
}
}
Expand All @@ -140,20 +140,19 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
if (entry.endsWith(".class")) {
// normalize with the os separator
entry = entry.replace(sep, ".").substring(0, entry.length() - 6);
checkClass(clazzes, entry, url);
checkClass(clazzes, entry, path);
}
return super.visitFile(file, attrs);
}
});
}
}
}

@SuppressForbidden(reason = "proper use of URL to reduce noise")
static void checkClass(Map<String,URL> clazzes, String clazz, URL url) {
URL previous = clazzes.put(clazz, url);

static void checkClass(Map<String,Path> clazzes, String clazz, Path jarpath) {
Path previous = clazzes.put(clazz, jarpath);
if (previous != null) {
if (previous.equals(url)) {
if (previous.equals(jarpath)) {
if (clazz.startsWith("org.apache.xmlbeans")) {
return; // https://issues.apache.org/jira/browse/XMLBEANS-499
}
Expand All @@ -162,7 +161,7 @@ static void checkClass(Map<String,URL> clazzes, String clazz, URL url) {
// UweSays: It can, but should be considered as bug :-)
throw new IllegalStateException("jar hell!" + System.lineSeparator() +
"class: " + clazz + System.lineSeparator() +
"exists multiple times in jar: " + url.getPath() + " !!!!!!!!!");
"exists multiple times in jar: " + jarpath + " !!!!!!!!!");
} else {
if (clazz.startsWith("org.apache.log4j")) {
return; // go figure, jar hell for what should be System.out.println...
Expand All @@ -172,8 +171,8 @@ static void checkClass(Map<String,URL> clazzes, String clazz, URL url) {
}
throw new IllegalStateException("jar hell!" + System.lineSeparator() +
"class: " + clazz + System.lineSeparator() +
"jar1: " + previous.getPath() + System.lineSeparator() +
"jar2: " + url.getPath());
"jar1: " + previous + System.lineSeparator() +
"jar2: " + jarpath);
}
}
}
Expand Down