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

Wrong MethodParameters on capturing local class with multiple constructors

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8, 9
    • tools
    • b99
    • Verified

      Compiling the following class with -parameters generates buggy code:

      class TestMethodParameters {
          void test(final int i) {
              class L {
                  L(final int j) {
                     this(new Object() { void test() { int x = i; } });
                  }
                  L(Object o) { }
              }
              new L(i) { };
          }
      }


      Javap shows:

      WhichImplicitThis9$1L(int);
          descriptor: (LWhichImplicitThis9;II)V
          flags:
          Code:
            stack=6, locals=4, args_size=4
               0: aload_0
               1: aload_1
               2: new #1 // class WhichImplicitThis9$1L$1
               5: dup
               6: aload_1
               7: iload_3
               8: invokespecial #2 // Method WhichImplicitThis9$1L$1."<init>":(LWhichImplicitThis9;I)V
              11: iload_3
              12: invokespecial #3 // Method "<init>":(LWhichImplicitThis9;Ljava/lang/Object;I)V
              15: return
            LineNumberTable:
              line 122: 0
              line 123: 15
      Error: java.lang.reflect.InvocationTargetException
            MethodParameters: length = 0x9
             03 00 0D 80 10 00 14 00 10
          Signature: #22 // (I)V


      As it can be seen, the MethodParameters attribute is ill formed:

       03 00 0D 80 10 00 14 00 10

      This means that there are 3 entries (leading 03) - but only two pairs of name and values (both u2) can be found.

      The other constructor is fine:

      WhichImplicitThis9$1L(java.lang.Object);
          descriptor: (LWhichImplicitThis9;Ljava/lang/Object;I)V
          flags:
          Code:
            stack=2, locals=4, args_size=4
               0: aload_0
               1: aload_1
               2: putfield #4 // Field this$0:LWhichImplicitThis9;
               5: aload_0
               6: iload_3
               7: putfield #5 // Field val$i:I
              10: aload_0
              11: invokespecial #6 // Method java/lang/Object."<init>":()V
              14: return
            LineNumberTable:
              line 124: 0
          MethodParameters:
            Name Flags
            this$0 final mandated
            o
            val$i final synthetic


            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: