diff --git a/server/src/main/java/org/opensearch/plugins/PluginsService.java b/server/src/main/java/org/opensearch/plugins/PluginsService.java index c7564d082a6..d0aa6ab735c 100644 --- a/server/src/main/java/org/opensearch/plugins/PluginsService.java +++ b/server/src/main/java/org/opensearch/plugins/PluginsService.java @@ -662,6 +662,7 @@ public class PluginsService implements ReportingService { return null; }); + logger.debug("Loading plugin [" + name + "]..."); Class pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader); if (loader != pluginClass.getClassLoader()) { throw new IllegalStateException("Plugin [" + name + "] must reference a class loader local Plugin class [" @@ -700,8 +701,8 @@ public class PluginsService implements ReportingService { private Class loadPluginClass(String className, ClassLoader loader) { try { return Class.forName(className, false, loader).asSubclass(Plugin.class); - } catch (ClassNotFoundException e) { - throw new OpenSearchException("Could not find plugin class [" + className + "]", e); + } catch (Throwable t) { + throw new OpenSearchException("Unable to load plugin class [" + className + "]", t); } } diff --git a/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java b/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java index e7d6d3810b8..9f4473fa07b 100644 --- a/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java +++ b/server/src/test/java/org/opensearch/plugins/PluginsServiceTests.java @@ -734,6 +734,30 @@ public class PluginsServiceTests extends OpenSearchTestCase { TestPlugin.class.getName() + "] (class loader [" + PluginsServiceTests.class.getClassLoader() + "])"))); } + public void testPluginLoadFailure() throws IOException { + final Path pathHome = createTempDir(); + final Path plugins = pathHome.resolve("plugins"); + final Path fake = plugins.resolve("fake"); + + PluginTestUtil.writePluginProperties( + fake, + "description", "description", + "name", "fake", + "version", "1.0.0", + "opensearch.version", Version.CURRENT.toString(), + "java.version", System.getProperty("java.specification.version"), + "classname", "DummyClass"); // This class is not present in Path, hence plugin loading will throw ClassNotFoundException + + final Settings settings = + Settings.builder() + .put("path.home", pathHome) + .put("plugin.mandatory", "fake") + .build(); + RuntimeException exception = expectThrows(RuntimeException.class, () -> newPluginsService(settings)); + assertTrue(exception.getCause() instanceof ClassNotFoundException); + assertThat(exception, hasToString(containsString("Unable to load plugin class [DummyClass]"))); + } + public void testExtensiblePlugin() { TestExtensiblePlugin extensiblePlugin = new TestExtensiblePlugin(); PluginsService.loadExtensions(Collections.singletonList(