Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8302260

VarHandle.describeConstable() fails to return a nominal descriptor for static public fields

XMLWordPrintable

      There are classes (attached to this issue)

      public class CTestClass extends CTestSuperClass implements ITestInterfaceA {
          public static String ctestString = "CTestClass";
          public static long ctestLong = 1l;
      }
      &&
      public class CTestSuperClass {
          public static String stringField = "CTestSuperClass";
          public static long longField = 100L;
          public static String stringField2 = "CTestSuperClass2";
          public static long longField2 = 102L;
      }
      &&
      public interface ITestInterfaceA {
          String stringField = "ITestInterfaceA";
          long longField = 10l;
          String stringField3 = "ITestInterfaceA3";
          long longField3 = 13L;
      }

      and test runner that has the sequence of method invocations:

      VarHandle vh = MethodHandles.lookup().findStaticVarHandle(CTestClass.class,”longField”, long.class);
      // or
      VarHandle vh = MethodHandles.lookup().findStaticVarHandle(CTestClass.class,”stringField”, Stirng.class);
      // and
      VarHandle.VarHandleDesc vhd = vh.describeConstable();

      then vhd will erroneously describe : VarHandleDesc[static CTestClass.ctestLong:long] or VarHandleDesc[static CTestClass.ctestString:String]
      It happens only if CTestClass has both static fields

      otherwise if for example the field String ctestString is removed from the CTestClass.class then vh.describeConstable throws the exception:

      java.lang.InternalError: Static field not found at offset
      at java.base/java.lang.invoke.VarHandles.getStaticFieldFromBaseAndOffset(VarHandles.java:197)
      at java.base/java.lang.invoke.VarHandleLongs$FieldStaticReadOnly.describeConstable(VarHandleLongs.java:410)
          
      Thus VarHandle.describeConstable hasn’t been working since fix of JDK-8297757
      Also any exception thrown by describeConstable should be mentioned in the specification

            mchung Mandy Chung (Inactive)
            lkuskov Leonid Kuskov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: