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

Fix for JarHell Bootstrap Check can yield false positives #76217

Merged
merged 3 commits into from
Aug 10, 2021
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 @@ -567,8 +567,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) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the original problem could still occur for another unknown exception. Instead of specializing other exception types, let’s specialize the only one we throw for jar hell, IllegalStateException. Then the general exception can catch all the others with a different message like “failed to load plugin foo while checking for jar hell”.

Copy link
Contributor Author

@BalasubramanyamEvani BalasubramanyamEvani Aug 8, 2021

Choose a reason for hiding this comment

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

Yes, it makes sense. I have made the changes to check only for IllegalStateException that gets specifically thrown, the general exception catches all the others

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 @@ -500,6 +500,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