Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isParentFirst method to QuarkusClassLoader #16617

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add isParentFirst method to QuarkusClassLoader
This can be used by extensions to determine if a class
would be loaded parent first or not.
Relates to: #16576 (comment)
geoand committed Apr 20, 2021

Verified

This commit was signed with the committer’s verified signature.
d-e-s-o Daniel Müller
commit 8485eeeda39f4e6e83e372f8e853d92604740ab4
Original file line number Diff line number Diff line change
@@ -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);
}