Skip to content

Commit

Permalink
Ensure only single instance for each classpath extension
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 14, 2024
1 parent 44a4042 commit 7b4d7d7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/src/main/java/org/opensearch/plugins/PluginsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public PluginsService(
pluginsLoaded.add(new Tuple<>(pluginInfo, plugin));
pluginsList.add(pluginInfo);
pluginsNames.add(pluginInfo.getName());
loadExtensions(pluginsLoaded);
}
loadExtensions(pluginsLoaded);

Set<Bundle> seenBundles = new LinkedHashSet<>();
List<PluginInfo> modulesList = new ArrayList<>();
Expand Down Expand Up @@ -571,9 +571,17 @@ private static void loadExtensionsForPlugin(ExtensiblePlugin extensiblePlugin, L
ExtensiblePlugin.ExtensionLoader extensionLoader = new ExtensiblePlugin.ExtensionLoader() {
@Override
public <T> List<T> loadExtensions(Class<T> extensionPointType) {
Set<Class<?>> seenClasses = new LinkedHashSet<>();
List<T> result = new ArrayList<>();

for (Plugin extendingPlugin : extendingPlugins) {
result.addAll(createExtensions(extensionPointType, extendingPlugin));
List<? extends T> extensions = createExtensions(extensionPointType, extendingPlugin);
for (T extension : extensions) {
// Only add if we haven't seen this class before, needed for classpath extensions for testing
if (seenClasses.add(extension.getClass())) {
result.add(extension);
}
}
}
return Collections.unmodifiableList(result);
}
Expand Down

0 comments on commit 7b4d7d7

Please sign in to comment.