Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-11861

ObjectStreamClass use of bridge.getXXX static fields does not confirm Unsafe API

    Details

      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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tomekadamski Tomasz Adamski
                Reporter:
                tomekadamski Tomasz Adamski
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: