Skip to content

Commit

Permalink
Emit better error messages for jarhell (#76217) (#76299)
Browse files Browse the repository at this point in the history
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 <balasubramanyam.evani@gmail.com>
  • Loading branch information
elasticsearchmachine and BalasubramanyamEvani committed Aug 10, 2021
1 parent 1100311 commit 08021b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,10 @@ static void checkBundleJarHell(Set<URL> classpath, Bundle bundle, Map<String, Se
Set<URL> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Set<URL>> 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");
Expand Down

0 comments on commit 08021b1

Please sign in to comment.