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

Scala 3 lazy vals break FieldSerializer #882

Closed
nvollmar opened this issue Feb 4, 2022 · 3 comments · Fixed by #883
Closed

Scala 3 lazy vals break FieldSerializer #882

nvollmar opened this issue Feb 4, 2022 · 3 comments · Fixed by #883

Comments

@nvollmar
Copy link

nvollmar commented Feb 4, 2022

Scala 3 changed the implementation of lazy vals. Classes containing a lazy val end up with a field called 0bitmap$1:

Compiled from "Test.scala"
public class Test implements scala.Product,java.io.Serializable {
  public static final long OFFSET$0;
  public long 0bitmap$1;
  private final byte a;
  ...

Trying to serialize an instance of such a class fails with

Cause: java.lang.ClassFormatError: Illegal field name "0bitmap$1" in class io/altoo/akka/serialization/kryo/TestFieldAccess
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
	at com.esotericsoftware.reflectasm.AccessClassLoader.defineClass(AccessClassLoader.java:78)
	at com.esotericsoftware.reflectasm.AccessClassLoader.defineAccessClass(AccessClassLoader.java:57)
	at com.esotericsoftware.reflectasm.FieldAccess.get(FieldAccess.java:173)
	at com.esotericsoftware.kryo.serializers.CachedFields.addField(CachedFields.java:147)
	at com.esotericsoftware.kryo.serializers.CachedFields.rebuild(CachedFields.java:99)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.<init>(FieldSerializer.java:82)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.<init>(FieldSerializer.java:68)
	at jdk.internal.reflect.GeneratedConstructorAccessor27.newInstance(Unknown Source)
@theigl
Copy link
Collaborator

theigl commented Feb 4, 2022

@nvollmar: Could you try it against this branch: https://github.com/EsotericSoftware/kryo/tree/scala-lazy-val

With the added catch clause, FieldSerializer should fall back to standard reflection.

@nvollmar
Copy link
Author

nvollmar commented Feb 4, 2022

Quickly ran my test case against a build of that branch and I can confirm this fixes the issue 👍

@theigl
Copy link
Collaborator

theigl commented Feb 4, 2022

Great! I'll apply this fix and will release a new Kryo version in the coming days.

Please report the issue to @reflect. It is unlikely that it will be fixed since the project is not actively maintained, but it makes sense to document it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants