Skip to content

java.lang.ClassCastException while serializing a complex Java object #2085

Open
@cquezel

Description

@cquezel

Search before asking

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

Version

Fury 0.10.0
Open JDK 21
Windows

Component(s)

Java

Minimal reproduce step

I am very sorry but I cannot reproduce this using a simple unit test. It is a long data import process which is ultimately serialized in a 1,2 GB object on disk. I hope the stack trace can provide a sufficient hint at the problem.

This is the Fury code

private static <T> void écrireFury(FileOutputStream fos, T objet) throws IOException {
	Fury fury = Fury.builder().withLanguage(Language.JAVA)
		.requireClassRegistration(false)
		.withRefTracking(true)
		.build();
	byte[] bytes = fury.serialize(objet);		
	fos.write(bytes);
}

To replace the Java:

private static <T> void écrireJava(FileOutputStream fos, T objet) throws FileNotFoundException, IOException {
	try (ObjectOutput oos = new ObjectOutputStream(fos)) {
		oos.writeObject(objet);
	}
}

What did you expect to see?

A successful serialization to disk.

What did you see instead?

Caused by: java.lang.ClassCastException: class myproject.modelecompletimpl.GroupeRéguliersImpl cannot be cast to class myproject.modelecompletimpl.ModuleImpl (myproject.modelecompletimpl.GroupeRéguliersImpl and myproject.modelecompletimpl.ModuleImpl are in module myproject.modelecompletimpl of loader 'app')
at myproject.modelecompletimpl.ModuleImplFuryRefCodec_0.write(ModuleImplFuryRefCodec_0.java:1743) ~[?:?]
at myproject.modelecompletimpl.NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.writeChunk$(NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.java:193) ~[?:?]
at myproject.modelecompletimpl.NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.writeFields1$(NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.java:228) ~[?:?]
at myproject.modelecompletimpl.NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.write(NoeudsQuiFontRéférenceAuCatalogueImplFuryRefCodec_0.java:463) ~[?:?]
at [email protected]/org.apache.fury.Fury.writeNonRef(Fury.java:479) ~[fury-core-0.10.0.jar:?]
at [email protected]/org.apache.fury.serializer.ArraySerializers$ObjectArraySerializer.write(ArraySerializers.java:106) ~[fury-core-0.10.0.jar:?]
at [email protected]/org.apache.fury.serializer.ArraySerializers$ObjectArraySerializer.write(ArraySerializers.java:43) ~[fury-core-0.10.0.jar:?]
... a thousand more lines

Anything Else?

No response

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