Skip to content
Permalink
Browse files

[JENKINS-23784] Avoid acquiring ClassLoader locks. (#2581)

  • Loading branch information...
jglick authored and oleg-nenashev committed Oct 10, 2016
1 parent 59cec45 commit a04e2f9836263f7ae5e68617f5bafde18e594446
Showing with 6 additions and 6 deletions.
  1. +6 −6 core/src/main/java/hudson/util/MaskingClassLoader.java
@@ -25,12 +25,12 @@

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Enumeration;
import java.util.Collections;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* {@link ClassLoader} that masks a specified set of classes
@@ -45,9 +45,9 @@
/**
* Prefix of the packages that should be hidden.
*/
private final List<String> masksClasses = new ArrayList<String>();
private final List<String> masksClasses = new CopyOnWriteArrayList<>();

private final List<String> masksResources = new ArrayList<String>();
private final List<String> masksResources = new CopyOnWriteArrayList<>();

public MaskingClassLoader(ClassLoader parent, String... masks) {
this(parent, Arrays.asList(masks));
@@ -66,7 +66,7 @@ public MaskingClassLoader(ClassLoader parent, Collection<String> masks) {
}

@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
for (String mask : masksClasses) {
if(name.startsWith(mask))
throw new ClassNotFoundException();
@@ -76,7 +76,7 @@ public MaskingClassLoader(ClassLoader parent, Collection<String> masks) {
}

@Override
public synchronized URL getResource(String name) {
public URL getResource(String name) {
if (isMasked(name)) return null;

return super.getResource(name);
@@ -89,7 +89,7 @@ public synchronized URL getResource(String name) {
return super.getResources(name);
}

public synchronized void add(String prefix) {
public void add(String prefix) {
masksClasses.add(prefix);
if(prefix !=null){
masksResources.add(prefix.replace(".","/"));

0 comments on commit a04e2f9

Please sign in to comment.
You can’t perform that action at this time.