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

Different orders of anonymous classes

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u151
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Affected versions:

      Oracle

      javac 1.8.0_151
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      Eclipse

      Eclipse Compiler for Java(TM) v20150120-1634, 3.10.2.


      A DESCRIPTION OF THE PROBLEM :
      Accordingly to the Java Language Specification (Section 13.1 - The Form of a Binary) "The binary name of an anonymous class consists of the binary name of its immediately enclosing type, followed by $, followed by a nonempty sequence of digits". As nothing about the order of multiple anonymous classes is specified, a different result is returned when executing the following program considering bytecodes generated by different compilers:

      public class A {
         public String toString() {
            return new B(){}.toString();
         }
         private static final B b = new B() {};
      }

      public class B {}

      public class D {
         public static void main(String[] args) throws ClassNotFoundException {
            Class c = Class.forName("A$2");
            System.out.println(c.getEnclosingMethod());
         }
      }

      Steps to reproduce:

       * Compile above program using Eclipse and Oracle javac compilers
       * Run it using Oracle HotSpot java

      Current result:

       * Using a bytecode generated by the Eclipse Compiler:

         public String toString()

       * Using a bytecode generated by the Oracle javac compiler:

         null

      Expected result:

       The same result.


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: