Skip to content

Commit

Permalink
Add isParentFirst method to QuarkusClassLoader
Browse files Browse the repository at this point in the history
This can be used by extensions to determine if a class
would be loaded parent first or.
Relates to: quarkusio#16576 (comment)
  • Loading branch information
geoand committed Apr 19, 2021
1 parent 0cd6553 commit 1d48b75
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ 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

0 comments on commit 1d48b75

Please sign in to comment.