Skip to content

Commit

Permalink
fix parent classloader load classes in children classloaders
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Nov 21, 2024
1 parent a6410c5 commit bb70253
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,26 @@ static <T> Class<? extends Serializer<T>> loadOrGenCodecClass(
beanClassClassLoader = fury.getClass().getClassLoader();
}
ClassResolver classResolver = fury.getClassResolver();
codeGenerator = getCodeGenerator(fury, beanClassClassLoader, classResolver);
ClassLoader classLoader =
codeGenerator.compile(
Collections.singletonList(compileUnit), compileState -> compileState.lock.lock());
String className = codecBuilder.codecQualifiedClassName(beanClass);
try {
return (Class<? extends Serializer<T>>) classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Impossible because we just compiled class", e);
}
}

private static CodeGenerator getCodeGenerator(
Fury fury, ClassLoader beanClassClassLoader, ClassResolver classResolver) {
CodeGenerator codeGenerator;
try {
// generated code imported fury classes.
beanClassClassLoader.loadClass(Fury.class.getName());
if (beanClassClassLoader.loadClass(Fury.class.getName()) != Fury.class) {
throw new ClassNotFoundException();
}
codeGenerator = classResolver.getCodeGenerator(beanClassClassLoader);
if (codeGenerator == null) {
codeGenerator = CodeGenerator.getSharedCodeGenerator(beanClassClassLoader);
Expand All @@ -107,14 +124,6 @@ static <T> Class<? extends Serializer<T>> loadOrGenCodecClass(
classResolver.setCodeGenerator(loaders, codeGenerator);
}
}
ClassLoader classLoader =
codeGenerator.compile(
Collections.singletonList(compileUnit), compileState -> compileState.lock.lock());
String className = codecBuilder.codecQualifiedClassName(beanClass);
try {
return (Class<? extends Serializer<T>>) classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Impossible because we just compiled class", e);
}
return codeGenerator;
}
}

0 comments on commit bb70253

Please sign in to comment.