Skip to content

[Java] ClassCastException when deserializing certain records (interpreter mode) #2257

Open
@gudzpoz

Description

@gudzpoz

Search before asking

  • I had searched in the issues and found no similar issues.

Version

Fury: 'org.apache.fury:fury-core:0.10.2'
JDK: GraalVM 23.0.2+7.1 (build 23.0.2+7-jvmci-b01)

Component(s)

Java

Minimal reproduce step

    @Test
    public void testNumberListRecord() {
        Fury fury = Fury.builder()
                .withLanguage(Language.JAVA)
                .withAsyncCompilation(true)
                .build();
        fury.register(NumberListRecord.class);
        fury.register(IntArrayList.class);
        byte[] bytes = fury.serialize(new NumberListRecord(1L, new ArrayList<>()));
        fury.deserialize(bytes); // <-- ClassCastException
    }

    record NumberListRecord(Number n, List<Object> list) {
    }

What did you expect to see?

The test above passes.

What did you see instead?

Cannot cast java.util.ArrayList to java.lang.Number
java.lang.ClassCastException: Cannot cast java.util.ArrayList to java.lang.Number
	at java.base/java.lang.Class.cast(Class.java:4139)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:735)
	at org.apache.fury.serializer.ObjectSerializer.read(ObjectSerializer.java:241)
	at org.apache.fury.Fury.readDataInternal(Fury.java:990)
	at org.apache.fury.Fury.readRef(Fury.java:874)
	at org.apache.fury.Fury.deserialize(Fury.java:806)
	at org.apache.fury.Fury.deserialize(Fury.java:727)
	at party.iroiro.juicemacs.elisp.runtime.pdump.DumpUtilsTest.testNumberListRecord(DumpUtilsTest.java:164)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)

Anything Else?

I have also tested with the following records:

    record NumberListRecord(Integer n, List<Object> list) {
        // This one passes the test.
    }
    record NumberListRecord(AutoClosable n, List<Object> list) {
        // This one fails.
    }

Also, setting withAsyncCompilation(false) also removes the error. So the bug seems to be in the interpreted serializer.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions