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

Anonymous class modifier is incorrect

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7u40
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_40"
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :

      Darwin ABHISHK2-M-40RU 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Anonymous class is generated with class modifier as static. The spec says differently.

      http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.9.5

      ===
      An anonymous class declaration is automatically derived from a class instance creation expression by the Java compiler.

      An anonymous class is never abstract (§8.1.1.1).

      An anonymous class is always implicitly final (§8.1.1.2).

      An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.1).
      ===

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In the following code, the printed modifier is "static" when compiled with javac.


      import java.lang.reflect.Modifier;

      public class MyClass {
        public static interface TestInterface{
          public void test();
        }

        public static void main(String [] args){
          TestInterface t = new TestInterface() {
            @Override
            public void test() {
              System.out.println("created...");
            }
          };

          int mods = t.getClass().getModifiers();
          System.out.println("Modifiers are: " + Modifier.toString(mods));
        }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Modifiers would be empty
      ACTUAL -
      Modifier was "static"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import java.lang.reflect.Modifier;

      public class MyClass {
        public static interface TestInterface{
          public void test();
        }

        public static void main(String [] args){
          TestInterface t = new TestInterface() {
            @Override
            public void test() {
              System.out.println("created...");
            }
          };

          int mods = t.getClass().getModifiers();
          System.out.println("Modifiers are: " + Modifier.toString(mods));
        }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: