Details
-
Bug
-
Resolution: Done
-
Major
-
16.0.0.Final
-
None
Description
ObjectStreamClass must use staticFieldBase object instead of class object to get a field value, see for example the code
openjdk-orb-jdk9/src/main/java/com/sun/corba/se/impl/io/ObjectStreamClass.java
final Field f = cl.getDeclaredField("serialVersionUID"); int mods = f.getModifiers(); // SerialBug 5: static final SUID should be read if (Modifier.isStatic(mods) && Modifier.isFinal(mods) ) { long offset = bridge.staticFieldOffset(f); suid = bridge.getLong(cl, offset);
Here are excerpts from sun.misc.Unsafe doc:
public native Object staticFieldBase(Field f)
Report the location of a given static field, in conjunction with #staticFieldOffset.
...
public int getInt(Object o, int offset) // getLong, etc.
...
The results are undefined unless one of the following cases is true:
...
The offset and object reference o (either null or
non-null) were both obtained via #staticFieldOffset
and #staticFieldBase (respectively) from the
reflective Field representation of some Java field.
With OpenJDK VMs using the class object incidentally works but with other VMs (Azul Zing for example) this fails.