From 08021b13d6ff63480864e0cbdf10116d4ec80adc Mon Sep 17 00:00:00 2001 From: elasticsearchmachine <58790826+elasticsearchmachine@users.noreply.github.com> Date: Tue, 10 Aug 2021 13:53:30 -0400 Subject: [PATCH] Emit better error messages for jarhell (#76217) (#76299) When checking for jarhell while loading plugins, exceptions other than jarhell can occur. The wrapped exception message in these cases refers to jarhell failing, but in actuality it was eg a filesystem error. This commit separates the two cases, jarhell failure and other failure. Co-authored-by: E Bala --- .../elasticsearch/plugins/PluginsService.java | 6 ++++-- .../plugins/PluginsServiceTests.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java index 43f2c25e3f01a..fee5d981fcc5d 100644 --- a/server/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/server/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -607,8 +607,10 @@ static void checkBundleJarHell(Set classpath, Bundle bundle, Map union = new HashSet<>(classpath); union.addAll(bundle.urls); JarHell.checkJarHell(union, logger::debug); - } catch (Exception e) { - throw new IllegalStateException("failed to load plugin " + bundle.plugin.getName() + " due to jar hell", e); + } catch (final IllegalStateException ise) { + throw new IllegalStateException("failed to load plugin " + bundle.plugin.getName() + " due to jar hell", ise); + } catch (final Exception e) { + throw new IllegalStateException("failed to load plugin " + bundle.plugin.getName() + " while checking for jar hell", e); } } diff --git a/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index d39916753e9d4..2b4293a410389 100644 --- a/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -530,6 +530,26 @@ public void testJarHellDuplicateClassWithCore() throws Exception { assertThat(e.getCause().getMessage(), containsString("Level")); } + public void testJarHellWhenExtendedPluginJarNotFound() throws Exception { + Path pluginDir = createTempDir(); + Path pluginJar = pluginDir.resolve("dummy.jar"); + + Path otherDir = createTempDir(); + Path extendedPlugin = otherDir.resolve("extendedDep-not-present.jar"); + + PluginInfo info = new PluginInfo("dummy", "desc", "1.0", Version.CURRENT, "1.8", + "Dummy", Arrays.asList("extendedPlugin"), false, PluginType.ISOLATED, "", false); + + PluginsService.Bundle bundle = new PluginsService.Bundle(info, pluginDir); + Map> transitiveUrls = new HashMap<>(); + transitiveUrls.put("extendedPlugin", Collections.singleton(extendedPlugin.toUri().toURL())); + + IllegalStateException e = expectThrows(IllegalStateException.class, () -> + PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveUrls)); + + assertEquals("failed to load plugin dummy while checking for jar hell", e.getMessage()); + } + public void testJarHellDuplicateClassWithDep() throws Exception { Path pluginDir = createTempDir(); Path pluginJar = pluginDir.resolve("plugin.jar");