diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java index 1047ec5a3dbc..10b0d179fdd7 100644 --- a/core/src/main/java/hudson/ClassicPluginStrategy.java +++ b/core/src/main/java/hudson/ClassicPluginStrategy.java @@ -86,11 +86,6 @@ public class ClassicPluginStrategy implements PluginStrategy { private final PluginManager pluginManager; - /** - * All the plugins eventually delegate this classloader to load core, servlet APIs, and SE runtime. - */ - private final MaskingClassLoader coreClassLoader = new MaskingClassLoader(getClass().getClassLoader()); - public ClassicPluginStrategy(PluginManager pluginManager) { this.pluginManager = pluginManager; } @@ -235,16 +230,8 @@ private static Manifest loadLinkedManifest(File archive) throws IOException { fix(atts, optionalDependencies); - // Register global classpath mask. This is useful for hiding JavaEE APIs that you might see from the container, - // such as database plugin for JPA support. The Mask-Classes attribute is insufficient because those classes - // also need to be masked by all the other plugins that depend on the database plugin. - String masked = atts.getValue("Global-Mask-Classes"); - if (masked != null) { - for (String pkg : masked.trim().split("[ \t\r\n]+")) - coreClassLoader.add(pkg); - } - - ClassLoader dependencyLoader = new DependencyClassLoader(coreClassLoader, archive, Util.join(dependencies, optionalDependencies), pluginManager); + ClassLoader dependencyLoader = new DependencyClassLoader( + getClass().getClassLoader(), archive, Util.join(dependencies, optionalDependencies), pluginManager); dependencyLoader = getBaseClassLoader(atts, dependencyLoader); return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL, diff --git a/core/src/main/java/hudson/util/MaskingClassLoader.java b/core/src/main/java/hudson/util/MaskingClassLoader.java index efb05831ccce..74bbbe1a9863 100644 --- a/core/src/main/java/hudson/util/MaskingClassLoader.java +++ b/core/src/main/java/hudson/util/MaskingClassLoader.java @@ -31,7 +31,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.stream.Collectors; /** * {@link ClassLoader} that masks a specified set of classes @@ -46,9 +46,9 @@ public class MaskingClassLoader extends ClassLoader { /** * Prefix of the packages that should be hidden. */ - private final List masksClasses = new CopyOnWriteArrayList<>(); + private final List masksClasses; - private final List masksResources = new CopyOnWriteArrayList<>(); + private final List masksResources; static { registerAsParallelCapable(); @@ -60,14 +60,13 @@ public MaskingClassLoader(ClassLoader parent, String... masks) { public MaskingClassLoader(ClassLoader parent, Collection masks) { super(parent); - this.masksClasses.addAll(masks); + this.masksClasses = List.copyOf(masks); /* * The name of a resource is a '/'-separated path name */ - for (String mask : masks) { - masksResources.add(mask.replace('.', '/')); - } + this.masksResources = + masks.stream().map(mask -> mask.replace('.', '/')).collect(Collectors.toUnmodifiableList()); } @Override @@ -94,13 +93,6 @@ public Enumeration getResources(String name) throws IOException { return super.getResources(name); } - public void add(String prefix) { - masksClasses.add(prefix); - if (prefix != null) { - masksResources.add(prefix.replace('.', '/')); - } - } - private boolean isMasked(String name) { for (String mask : masksResources) { if (name.startsWith(mask))