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

Lookup::defineHiddenClass should throw ClassFormatError if the constant_pool entry at the this_class index is not Class_info structure

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 15
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:

      Description

      Tested method: MethodHandles.Lookup defineHiddenClass
      Assertion: The value of this_class must be a valid index in the constant_pool table, and the entry at that index must be a valid CONSTANT_Class_info structure.

      JVMS: 5.3.5. Deriving a Class from a class File Representation
       If the purported representation is not a ClassFile structure (§4.1, §4.8), loading throws an instance of ClassFormatError.

      Expected exception:
      ClassFormatError - if bytes is not a ClassFile structure

      Thrown:
      IllegalArgumentException - if bytes is not a class or interface or denotes a class in a different package than the lookup class



      The constant pool is:

      // this_class refers to NameAndType (not Class_info)
      class javasoft/sqe/tests/api/java/lang/invoke/MethodHandles/Lookup/TestClass02n03 {
        0xCAFEBABE;
        0; // minor version
        59; // version
        [] { // Constant Pool
          ; // first element is empty
          Method #2 #3; // #1
          class #4; // #2
          NameAndType #5 #6; // #3
          Utf8 "java/lang/Object"; // #4
          Utf8 "<init>"; // #5
          Utf8 "()V"; // #6
          class #8; // #7
          Utf8 "javasoft/sqe/tests/api/java/lang/invoke/MethodHandles/Lookup/TestInterface02n01"; // #8
          String #10; // #9
          Utf8 "TestInterface02p01"; // #10
          class #12; // #11
          Utf8 "javasoft/sqe/tests/api/java/lang/invoke/MethodHandles/Lookup/TestClass02n03"; // #12
          Utf8 "Code"; // #13
          Utf8 "LineNumberTable"; // #14
          Utf8 "getString"; // #15
          Utf8 "()Ljava/lang/String;"; // #16
          Utf8 "SourceFile"; // #17
          Utf8 "TestClass02n03.java"; // #18
        } // Constant Pool

        0x0031; // access
        #3; // this_cpx #11 -> #3
        #2; // super_cpx

      this byte code causes the exception:

      Expected exception java.lang.ClassFormatError was not thrown by testcase "testDefineHiddenClass0106a"
      "java.lang.IllegalArgumentException: <init> not in same package as lookup class: javasoft.sqe.tests.api.java.lang.invoke.MethodHandles.Lookup.DefineHiddenClass" was thrown instead
      java.lang.IllegalArgumentException: <init> not in same package as lookup class: javasoft.sqe.tests.api.java.lang.invoke.MethodHandles.Lookup.DefineHiddenClass
      at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:131)
      at java.base/java.lang.invoke.MethodHandles$Lookup.validateAndGetClassName(MethodHandles.java:2037)
      at java.base/java.lang.invoke.MethodHandles$Lookup.makeHiddenClassDefiner(MethodHandles.java:2102)
      at java.base/java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:1961)

        Attachments

          Activity

            People

            • Assignee:
              mchung Mandy Chung
              Reporter:
              lkuskov Leonid Kuskov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: