You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "gudzpoz (via GitHub)" <gi...@apache.org> on 2025/10/03 08:59:00 UTC

[I] [Java] Abstract class corner cases failing: arrays and enums [fory]

gudzpoz opened a new issue, #2695:
URL: https://github.com/apache/fory/issues/2695

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues.
   
   
   ### Version
   
   OS: ArchLinux (6.16.7-zen1-1-zen)
   Fory: 'org.apache.fory:fory-core:0.13.0-SNAPSHOT' (Sep 30)
   Failing JDK: GraalVM 23.0.2+7.1 (build 23.0.2+7-jvmci-b01)
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   Corner case 1: `AbstractObject[]`:
   
   ```console
   $ git clone https://github.com/gudzpoz/fory-native-image-reproducer.git
   $ git checkout abstract-array
   $ ./gradlew run
   Caused by: org.apache.fory.exception.InsecureException: class org.example.App$AbstractObject is not registered, please check whether it's the type you want to serialize or a **vulnerability**. If safe, you should invoke `Fory#register` to register class,  which will have better performance by skipping classname serialization. If your env is 100% secure, you can also avoid this exception by disabling class registration check using `ForyBuilder#requireClassRegistration(false)`
   ```
   
   Corner case 2: Abstract enums: (failing only under native images)
   
   ```console
   $ git clone https://github.com/gudzpoz/fory-native-image-reproducer.git
   $ git checkout abstract-enum
   $ ./gradlew run # pass
   $ ./gradlew nativeCompile
   $ app/build/native/nativeCompile/test
   java.lang.RuntimeException: Class class org.example.App$MyEnum is not registered
   ```
   
   ### What did you expect to see?
   
   The tests should pass.
   
   ### What did you see instead?
   
   Corner case 1: `AbstractObject[]`:
   
   ```console
   Exception in thread "main" java.lang.ExceptionInInitializerError
   Caused by: org.apache.fory.exception.InsecureException: class org.example.App$AbstractObject is not registered, please check whether it's the type you want to serialize or a **vulnerability**. If safe, you should invoke `Fory#register` to register class,  which will have better performance by skipping classname serialization. If your env is 100% secure, you can also avoid this exception by disabling class registration check using `ForyBuilder#requireClassRegistration(false)`
           at org.apache.fory.resolver.ClassResolver.createSerializer(ClassResolver.java:1220)
           at org.apache.fory.resolver.ClassResolver.getClassInfo(ClassResolver.java:1135)
           at org.apache.fory.resolver.ClassResolver.createSerializer0(ClassResolver.java:1269)
           at org.apache.fory.resolver.ClassResolver.lambda$ensureSerializersCompiled$14(ClassResolver.java:1803)
           at org.apache.fory.collection.ForyObjectMap.forEach(ForyObjectMap.java:302)
           at org.apache.fory.resolver.ClassResolver.ensureSerializersCompiled(ClassResolver.java:1796)
           at org.apache.fory.Fory.ensureSerializersCompiled(Fory.java:1606)
           at org.example.App.<clinit>(App.java:20)
   ```
   
   Corner case 2: Abstract enums: (failing only under native images)
   
   ```console
   Exception in thread "main" org.apache.fory.exception.SerializationException: java.lang.RuntimeException: Class class org.example.App$MyEnum is not registered
   	at org.apache.fory.Fory.processSerializationError(Fory.java:360)
   	at org.apache.fory.Fory.serialize(Fory.java:329)
   	at org.apache.fory.Fory.serialize(Fory.java:277)
   	at org.example.App.main(App.java:31)
   	at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
   Caused by: java.lang.RuntimeException: Class class org.example.App$MyEnum is not registered
   	at org.apache.fory.resolver.TypeResolver.getSerializerClassFromGraalvmRegistry(TypeResolver.java:635)
   	at org.apache.fory.resolver.ClassResolver.getSerializerClass(ClassResolver.java:862)
   	at org.apache.fory.resolver.ClassResolver.getSerializerClass(ClassResolver.java:854)
   	at org.apache.fory.resolver.ClassResolver.createSerializer(ClassResolver.java:1260)
   	at org.apache.fory.resolver.ClassResolver.getOrUpdateClassInfo(ClassResolver.java:1182)
   	at org.apache.fory.resolver.ClassResolver.getRawSerializer(ClassResolver.java:847)
   	at org.example.AppForyRefCodec_0.<init>(AppForyRefCodec_0.java:38)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.core.methodhandles.Util_java_lang_invoke_MethodHandle.invokeInternal(Target_java_lang_invoke_MethodHandle.java:241)
   	at java.base@25/java.lang.invoke.MethodHandle.invokeBasic(MethodHandle.java:102)
   	at java.base@25/java.lang.invoke.MethodHandle.invokeBasic(MethodHandle.java:0)
   	at java.base@25/java.lang.invoke.Invokers$Holder.invoke_MT(Invokers$Holder)
   	at org.apache.fory.serializer.Serializers.newSerializer(Serializers.java:101)
   	at org.apache.fory.resolver.ClassResolver.createSerializer(ClassResolver.java:1261)
   	at org.apache.fory.resolver.ClassResolver.getOrUpdateClassInfo(ClassResolver.java:1182)
   	at org.apache.fory.Fory.write(Fory.java:401)
   	at org.apache.fory.Fory.serialize(Fory.java:323)
   	... 3 more
   ```
   
   ### Anything Else?
   
   This seems to fix the issues, but I'm not entirely sure how enums are serialized:
   
   ```diff
   diff --git c/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java w/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
   index 8b9eca8d..b36cc1ea 100644
   --- c/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
   +++ w/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
   @@ -1800,7 +1800,10 @@ public class ClassResolver extends TypeResolver {
                    createSerializer0(cls);
                  }
                  if (cls.isArray()) {
   -                createSerializer0(TypeUtils.getArrayComponent(cls));
   +                Class<?> component = TypeUtils.getArrayComponent(cls);
   +                if (isSerializable(component)) {
   +                  createSerializer0(component);
   +                }
                  }
                }
              });
   diff --git c/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java w/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
   index 4db04ecf..ea62ab3b 100644
   --- c/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
   +++ w/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
   @@ -444,6 +444,9 @@ public abstract class TypeResolver {
      public abstract ClassDef getTypeDef(Class<?> cls, boolean resolveParent);
    
      public final boolean isSerializable(Class<?> cls) {
   +    if (cls.isEnum()) {
   +      return true;
   +    }
        if (ReflectionUtils.isAbstract(cls) || cls.isInterface()) {
          return false;
        }
   ```
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3695594003

   Hi @gudzpoz , I opened a new PR #3095 , I think it should fix this issue now. I will make a new release in next 2 weeks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #2695: [Java] Abstract class corner cases failing: arrays and enums
URL: https://github.com/apache/fory/issues/2695


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "gudzpoz (via GitHub)" <gi...@apache.org>.
gudzpoz commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3448216853

   I don't think I can assign issues. @chaokunyang Would you pleaese assign them this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "gudzpoz (via GitHub)" <gi...@apache.org>.
gudzpoz commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3695307346

   @chaokunyang I just tested and, no, it does not resolve this issue.
   
   **The first case**
   
   The first `AbstractObject[]` case still throws the same exception, **whether or not it uses native images**.
   
   **The second case**
   
   Native image building fails with an error:
   
   ```
   Error: Feature defined by org.apache.fory.graalvm.feature.ForyGraalVMFeature unexpectedly failed with a(n) java.lang.IllegalArgumentException. Please report this problem to the authors of org.apache.fory.graalvm.feature.ForyGraalVMFeature.
   
   Caused by: java.lang.IllegalArgumentException: Class java.util.ImmutableCollections$MapN cannot be instantiated reflectively . It does not have a nullary constructor.
   
   	at org.graalvm.nativeimage/org.graalvm.nativeimage.hosted.RuntimeReflection.registerForReflectiveInstantiation(RuntimeReflection.java:312)
   	at org.apache.fory.graalvm.feature.ForyGraalVMFeature.registerForReflectiveInstantiation(ForyGraalVMFeature.java:110)
   	at org.apache.fory.graalvm.feature.ForyGraalVMFeature.registerClass(ForyGraalVMFeature.java:89)
   	at org.apache.fory.graalvm.feature.ForyGraalVMFeature.duringAnalysis(ForyGraalVMFeature.java:64)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$2(NativeImageGenerator.java:844)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:93)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$1(NativeImageGenerator.java:844)
   	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:179)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:841)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:569)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:534)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:548)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:761)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:163)
   	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:111)
   ```
   
   From the documentation page you linked, it seems this `GraalVmFeature` only addresses private constructors and records. And it does not seem quite relevant to this issue?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3448231190

   @rahuldas-404 assigned to you, thanks for contributing to apache fory


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3658935091

   Hi @gudzpoz , could you fory 0.14.0 out, and use fory `GraalVmFeature`: https://fory.apache.org/docs/docs/guide/graalvm_serialization#forygraalvmfeature-optional
   
   I think it should resolve this issue


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "rahuldas-404 (via GitHub)" <gi...@apache.org>.
rahuldas-404 commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3419915223

   Hi @gudzpoz , I'd love to try working on this issue. Could you please assign it to me?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] [Java] Abstract class corner cases failing: arrays and enums [fory]

Posted by "rahuldas-404 (via GitHub)" <gi...@apache.org>.
rahuldas-404 commented on issue #2695:
URL: https://github.com/apache/fory/issues/2695#issuecomment-3433890333

   @gudzpoz @chaokunyang if no one is working, please assign this to me


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org