Skip to content
Merged
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 @@ -1193,7 +1193,7 @@ public Serializer<?> getRawSerializer(Class<?> cls) {
@Override
public Class<? extends Serializer> getSerializerClass(Class<?> cls) {
boolean codegen =
supportCodegenForJavaSerialization(cls) && fory.getConfig().isCodeGenEnabled();
fory.getConfig().isCodeGenEnabled() && supportCodegenForJavaSerialization(cls);
return getSerializerClass(cls, codegen);
}

Expand Down Expand Up @@ -1341,7 +1341,7 @@ public Object id() {
public Class<? extends Serializer> getObjectSerializerClass(
Class<?> cls, JITContext.SerializerJITCallback<Class<? extends Serializer>> callback) {
boolean codegen =
supportCodegenForJavaSerialization(cls) && fory.getConfig().isCodeGenEnabled();
fory.getConfig().isCodeGenEnabled() && supportCodegenForJavaSerialization(cls);
return getObjectSerializerClass(cls, false, codegen, callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
public final class CodegenSerializer {

public static boolean supportCodegenForJavaSerialization(Class<?> cls) {
// bean class can be static nested class, but can't be a non-static inner class
// If a class is a static class, the enclosing class must not be null.
// If enclosing class is null, it must not be a static class.
// bean class can be static nested class, but can't be a non-static inner class.
// Check modifiers first to avoid loading the enclosing class unnecessarily —
// in classloader-isolated environments (e.g. OSGi, module systems) the enclosing
// class may not be visible, causing NoClassDefFoundError.
if (Modifier.isStatic(cls.getModifiers())) {
return true;
}
try {
return cls.getEnclosingClass() == null || Modifier.isStatic(cls.getModifiers());

return cls.getEnclosingClass() == null;
} catch (Throwable t) {
throw new RuntimeException(t);
// Enclosing class is not loadable — the class cannot be a valid non-static
// inner class in this context, so codegen is not applicable.
return false;
}
}

Expand Down
Loading