Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public Class getClass(Schema schema) {
return null;
Class<?> c = classCache.computeIfAbsent(name, n -> {
try {
return ClassUtils.forName(getClassLoader(), getClassName(schema));
return ClassUtils.forName(getClassName(schema));
} catch (ClassNotFoundException e) {
// This might be a nested namespace. Try using the last tokens in the
// namespace as an enclosing class by progressively replacing period
Expand All @@ -399,7 +399,7 @@ public Class getClass(Schema schema) {
while (lastDot != -1) {
nestedName.setCharAt(lastDot, '$');
try {
return ClassUtils.forName(getClassLoader(), nestedName.toString());
return ClassUtils.forName(nestedName.toString());
} catch (ClassNotFoundException ignored) {
}
lastDot = n.lastIndexOf('.', lastDot - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private Class getPropAsClass(Schema schema, String prop) {
return null;
try {
checkSecurity(name);
Class clazz = ClassUtils.forName(getData().getClassLoader(), name);
Class clazz = ClassUtils.forName(name);
return clazz;
} catch (ClassNotFoundException e) {
throw new AvroRuntimeException(e);
Expand Down
35 changes: 6 additions & 29 deletions lang/java/avro/src/main/java/org/apache/avro/util/ClassUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,11 @@ public static Class<?> forName(String className) throws ClassNotFoundException {
*/
public static Class<?> forName(Class<?> contextClass, String className) throws ClassNotFoundException {
Class<?> c = null;
if (contextClass.getClassLoader() != null) {
c = forName(className, contextClass.getClassLoader());
}
if (c == null && Thread.currentThread().getContextClassLoader() != null) {
if (Thread.currentThread().getContextClassLoader() != null) {
c = forName(className, Thread.currentThread().getContextClassLoader());
}
if (c == null) {
throw new ClassNotFoundException("Failed to load class" + className);
}
return c;
}

/**
* Loads a class using the class loader. 1. The class loader of the context
* class is being used. 2. The thread context class loader is being used. If
* both approaches fail, returns null.
*
* @param classLoader The classloader to use.
* @param className The name of the class to load
* @return The class or null if no class loader could load the class.
*/
public static Class<?> forName(ClassLoader classLoader, String className) throws ClassNotFoundException {
Class<?> c = null;
if (classLoader != null) {
c = forName(className, classLoader);
}
if (c == null && Thread.currentThread().getContextClassLoader() != null) {
c = forName(className, Thread.currentThread().getContextClassLoader());
if (c == null && contextClass.getClassLoader() != null) {
c = forName(className, contextClass.getClassLoader());
}
if (c == null) {
throw new ClassNotFoundException("Failed to load class" + className);
Expand All @@ -84,9 +61,9 @@ public static Class<?> forName(ClassLoader classLoader, String className) throws
* Loads a {@link Class} from the specified {@link ClassLoader} without throwing
* {@link ClassNotFoundException}.
*
* @param className
* @param classLoader
* @return
* @param className The name of the class to load
* @param classLoader The classloader to use.
* @return The class or null if no class loader could load the class.
*/
private static Class<?> forName(String className, ClassLoader classLoader) {
Class<?> c = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private Conversion getConversionByDescriptor(Descriptor descriptor) {
String dot = namespace.endsWith("$") ? "" : "."; // back-compatibly handle $

try {
Class clazz = ClassUtils.forName(getClassLoader(), namespace + dot + name);
Class clazz = ClassUtils.forName(namespace + dot + name);
return getConversionByClass(clazz);
} catch (ClassNotFoundException e) {
return null;
Expand Down