Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Component types on generic arrays are lost during (de-)serialization #1323

Closed
1 of 2 tasks
mtf90 opened this issue Jan 9, 2024 · 2 comments · Fixed by #1324
Closed
1 of 2 tasks

[Java] Component types on generic arrays are lost during (de-)serialization #1323

mtf90 opened this issue Jan 9, 2024 · 2 comments · Fixed by #1324
Labels
bug Something isn't working

Comments

@mtf90
Copy link
Contributor

mtf90 commented Jan 9, 2024

Search before asking

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

Version

  • 0.5.0-SNAPSHOT from the nightly builds (current HEAD is a80dce6)
  • OS: Linux x64
  • Java: fails on JDK 11/17/21

Component(s)

Java

Minimal reproduce step

public class App {

    public static void main(String[] args) {
        final Fury fury = Fury.builder().requireClassRegistration(false).build();
        final ArrayWrapper<String> wrapper = new ArrayWrapper<>(String.class, 2);

        wrapper.array[0] = "Hello";

        final byte[] bytes = fury.serialize(wrapper);
        final ArrayWrapper<String> deserialized = (ArrayWrapper<String>) fury.deserialize(bytes);

        deserialized.array[1] = "World";
    }

    static class ArrayWrapper<T> {

        private final T[] array;

        public ArrayWrapper(Class<T> clazz, int capacity) {
            this.array = (T[]) Array.newInstance(clazz, capacity);
        }
    }
}

What did you expect to see?

A successfull run of the program

What did you see instead?

Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Ljava.lang.String; ([Ljava.lang.Object; and [Ljava.lang.String; are in module java.base of loader 'bootstrap')

Anything Else?

It appears that the information about the component type (here String.class) are lost and the (de-) serializer simply assumes "Generic Type? => Object!". The problem here is that one cannot simply replace the Array.newInstance(clazz, capacity); with new Object[capacity]; because then the wrapper.array[0] = "Hello"; statement fails with the same error.

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@mtf90 mtf90 added the bug Something isn't working label Jan 9, 2024
@mtf90 mtf90 changed the title Component types on generic arrays are lost during (de-)serialization [Java] Component types on generic arrays are lost during (de-)serialization Jan 9, 2024
@chaokunyang
Copy link
Collaborator

Thanks @mtf90 , I can reproduce this bug locally. This is a bug in fury. Fury take Object[] as a final type, it skip writing class info for such types, so the deserialization got wrong type. I fixed it in #1324. Thanks again for reporting this bug.

@mtf90
Copy link
Contributor Author

mtf90 commented Jan 10, 2024

Seems like fury is not only blazing fast with serialization but also with bug fixes 😆. Thank you very much for the quick response. Looking forward to test the nightly once this is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants