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

Anonymous inner class in incorrectly non-public

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 6u26
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_26"
      Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
      Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux <...> 2.6.18-194.3.1.el5 #1 SMP Thu May 13 13:08:30 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Anonymous classes generated by javac are not final according to their modifiers available through Reflection API.

      As per JLS (15.9.5 Anonymous Class Declarations), anonymous inner classes are implicitly final. Indeed, since 1.6 javac appears to set the "final" modifier in the class file generated for an inner class. However, the modifier seems to be absent in the "InnerClasses" attribute of the enclosing class file, and apparently JVM uses this incorrect value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the test, run it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Inner class must have a final modifier, test should complete silently.
      ACTUAL -
      Test complains that the inner class is not final.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Modifier;

      public class AnonymousInnerTest {
          public static final Object value = new Object() {
              public String toString() {
                  return "*";
              }
          };

          public static void main(String[] args) {
              if (!Modifier.isFinal(value.getClass().getModifiers()))
                  System.err.println("anonymous inner class is not final, modifiers: "
                      + Integer.toHexString(value.getClass().getModifiers()));
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: