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

separate compilation affects inner class constructor parameter names

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • tbd
    • 9
    • tools
    • None

      In the following example, the parameter names for the constructor of the anonymous inner class in 'B' change depending on whether the sources are compiled separately or together. This occurs despite using -parameters, which should make the parameter names available during separate compilation.

      $ cat A.java
      class A {
       A(int x, int y) {}
      }
      $ cat B.java
      class B {
        {
          new A(1, 2) {};
        }
      }

      # when both sources are compiled together, the constructor parameters of the anonymous inner class in B are 'x' and 'y'

      $ javac -g -parameters A.java B.java
      $ javap -v B\$1
      ...
        B$1(B, int, int);
          descriptor: (LB;II)V
          flags: (0x0000)
          Code:
      ...
            LocalVariableTable:
              Start Length Slot Name Signature
                  0 12 0 this LB$1;
                  0 12 1 this$0 LB;
                  0 12 2 x I
                  0 12 3 y I
          MethodParameters:
            Name Flags
            this$0 final mandated
            x
            y

      # when B is compiled with A on the classpath, the constructor parameters of the anonymous inner class in B are 'x0' and 'x1'

      $ javac -g -parameters B.java
      $ javap -v B\$1
      ...
        B$1(B, int, int);
          descriptor: (LB;II)V
          flags: (0x0000)
          Code:
      ...
            LocalVariableTable:
              Start Length Slot Name Signature
                  0 12 0 this LB$1;
                  0 12 1 this$0 LB;
                  0 12 2 x0 I
                  0 12 3 x1 I
          MethodParameters:
            Name Flags
            this$0 final mandated
            x0
            x1

            vromero Vicente Arturo Romero Zaldivar
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: