diff --git a/plugin/src/main/java/org/elasticsearch/xpack/extensions/InstallXPackExtensionCommand.java b/plugin/src/main/java/org/elasticsearch/xpack/extensions/InstallXPackExtensionCommand.java index b3da5bc308a..0582052a671 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/extensions/InstallXPackExtensionCommand.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/extensions/InstallXPackExtensionCommand.java @@ -28,10 +28,12 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.ArrayList; import java.util.Comparator; import java.util.Collections; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -168,8 +170,7 @@ final class InstallXPackExtensionCommand extends EnvironmentAwareCommand { private void jarHellCheck(Path candidate) throws Exception { // create list of current jars in classpath // including the x-pack jars (see $ES_CLASSPATH in bin/extension script) - final List jars = new ArrayList<>(); - jars.addAll(Arrays.asList(JarHell.parseClassPath())); + final Set jars = new HashSet<>(JarHell.parseClassPath()); // add extension jars to the list Path extensionJars[] = FileSystemUtils.files(candidate, "*.jar"); @@ -180,7 +181,7 @@ final class InstallXPackExtensionCommand extends EnvironmentAwareCommand { // TODO: verify the classname exists in one of the jars! // check combined (current classpath + new jars to-be-added) - JarHell.checkJarHell(jars.toArray(new URL[jars.size()])); + JarHell.checkJarHell(jars); } /** diff --git a/plugin/src/main/java/org/elasticsearch/xpack/extensions/XPackExtensionsService.java b/plugin/src/main/java/org/elasticsearch/xpack/extensions/XPackExtensionsService.java index 69d1757e654..361d20bbd3e 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/extensions/XPackExtensionsService.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/extensions/XPackExtensionsService.java @@ -5,14 +5,6 @@ */ package org.elasticsearch.xpack.extensions; -import org.apache.logging.log4j.Logger; -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.bootstrap.JarHell; -import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.io.FileSystemUtils; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; - import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; @@ -23,9 +15,19 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +import org.apache.logging.log4j.Logger; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.bootstrap.JarHell; +import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; + import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory; public class XPackExtensionsService { @@ -132,9 +134,9 @@ public class XPackExtensionsService { // jar-hell check the bundle against the parent classloader and the x-pack classloader // pluginmanager does it, but we do it again, in case lusers mess with jar files manually try { - final List jars = new ArrayList<>(); + final Set jars = new LinkedHashSet<>(); // add the parent jars to the list - jars.addAll(Arrays.asList(JarHell.parseClassPath())); + jars.addAll(JarHell.parseClassPath()); // add the x-pack jars to the list ClassLoader xpackLoader = getClass().getClassLoader(); @@ -145,7 +147,7 @@ public class XPackExtensionsService { jars.addAll(bundle.urls); - JarHell.checkJarHell(jars.toArray(new URL[0])); + JarHell.checkJarHell(jars); } catch (Exception e) { throw new IllegalStateException("failed to load bundle " + bundle.urls + " due to jar hell", e); }