Skip to content

Commit

Permalink
Remove ClassLoader hacks for JDK 8 now that we've moved to Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent fbae578 commit 804e47f
Showing 1 changed file with 1 addition and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,6 @@ private String sanitizeName(String name) {
return name;
}

/**
* Returns true if the supplied class is a class that would be loaded parent-first
*/
public boolean isParentFirst(String name) {
if (name.startsWith(JAVA)) {
return true;
}

//even if the thread is interrupted we still want to be able to load classes
//if the interrupt bit is set then we clear it and restore it at the end
boolean interrupted = Thread.interrupted();
try {
ClassLoaderState state = getState();
synchronized (getClassLoadingLock(name)) {
String resourceName = sanitizeName(name).replace(".", "/") + ".class";
return parentFirst(resourceName, state);
}

} finally {
if (interrupted) {
//restore interrupt state
Thread.currentThread().interrupt();
}
}
}

private boolean parentFirst(String name, ClassLoaderState state) {
return parentFirst || state.parentFirstResources.contains(name);
}
Expand Down Expand Up @@ -249,7 +223,7 @@ private ClassLoaderState getState() {
} else {
List<ClassPathElement> list = elementMap.get(i);
if (list == null) {
elementMap.put(i, list = new ArrayList<>(2)); //default initial capacity of 10 is way too large
elementMap.put(i, list = new ArrayList<>());
}
list.add(element);
}
Expand Down Expand Up @@ -511,16 +485,6 @@ public List<ClassPathElement> getElementsWithResource(String name, boolean local
return ret;
}

public List<String> getLocalClassNames() {
List<String> ret = new ArrayList<>();
for (String name : getState().loadableResources.keySet()) {
if (name.endsWith(".class")) {
ret.add(name.substring(0, name.length() - 6).replace("/", "."));
}
}
return ret;
}

@SuppressWarnings("unused")
public Class<?> visibleDefineClass(String name, byte[] b, int off, int len) throws ClassFormatError {
return super.defineClass(name, b, off, len);
Expand Down Expand Up @@ -567,16 +531,6 @@ public void close() {
log.error("Failed to close " + element, e);
}
}
for (ClassPathElement element : bannedElements) {
//note that this is a 'soft' close
//all resources are closed, however the CL can still be used
//but after close no resources will be held past the scope of an operation
try (ClassPathElement ignored = element) {
//the close() operation is implied by the try-with syntax
} catch (Exception e) {
log.error("Failed to close " + element, e);
}
}
ResourceBundle.clearCache(this);

}
Expand Down

0 comments on commit 804e47f

Please sign in to comment.