Skip to content

Commit

Permalink
Try to find class resource to avoid exception
Browse files Browse the repository at this point in the history
The exception thrown here when we cannot find a class can be very
expensive at boot time. For most third-party extensions, this
exception will be raised twice for every bound method, due to
double-checking the classloader under lock a second time. By first
looking for a .class resource, we can avoid the expensive
exception if it is unlikely to succeed.
  • Loading branch information
headius committed Dec 18, 2023
1 parent 627d8d1 commit afba384
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

import java.io.PrintWriter;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -634,11 +635,13 @@ private static void loadReceiver(String typePath, JavaMethodDescriptor desc, Ski
private Class tryClass(String name, Class targetClass, Class expectedSuperclass) {
final Class c;
try {
if (classLoader == null) {
c = Class.forName(name, true, classLoader);
} else {
c = classLoader.loadClass(name);
URL resource = classLoader.findResource(name.replace('.', '/'));
if (resource == null) {
if (DEBUG) LOG.debug("could not find class file for " + name);
seenUndefinedClasses = true;
return null;
}
c = classLoader.loadClass(name);
} catch (ClassNotFoundException e) {
if (DEBUG) LOG.debug(e);
seenUndefinedClasses = true;
Expand Down

0 comments on commit afba384

Please sign in to comment.