Nov11 / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Public final fields are being set through ASM instead of reflection in FieldSerializer #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create and serialize a class with a public final field
2. Try to deserialize it

What is the expected output? What do you see instead?

A java.lang.IllegalAccessError is thrown when the ASM-generated helper class 
tries to set the field's value.

One would expect the changes in issue #15 to call setAccessible on the field, 
but because the field gets put into the publicFields array list in 
FieldSerializer.rebuildCachedFields, it is handled with ASM regardless of the 
fact that it's final.

What version of the Kryo are you using?

1.03

Please provide any additional information below.

The fix is very simple -- in the if statement in FieldSerializer.java that adds 
elements to publicFields (line 99 in Kryo 1.03), add the condition 
!Modifier.isFinal(modifiers).

Original issue reported on code.google.com by matei.za...@gmail.com on 9 Nov 2010 at 7:49

GoogleCodeExporter commented 8 years ago
I should add that I ran into this when I tried to use Kryo to serialize some 
Scala standard library classes, such as pairs. Scala uses immutable objects 
extensively, and they often have public final fields. They also often lack 
argument-less constructors (issue #5), so some optional support for 
ReflectionFactory would be appreciated. Right now I'm using the modified 
ReferenceFieldSerializer in memcached-session-manager.

Original comment by matei.za...@gmail.com on 9 Nov 2010 at 7:53

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r144.

Original comment by nathan.s...@gmail.com on 9 Feb 2011 at 9:43

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I get the same error message in combination with libGDX (0.9.2) and lwjgl 
(latest 2.8.3) and Kryo 1.04.
The serialization of the normal public float variable (not final!) works fine 
in libGDX Desktop and Android package, but not in the applet. Also double 
checked, if the signing process with jarsigner was ok (META-INF/MANIFEST.MF).

Thanks for any useful tips!

Original comment by pejolaga...@gmail.com on 21 Jan 2012 at 11:45