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

Bad error message for implicit access to 'this' in static context

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • generic
    • solaris_2.5.1

      A gjc vs. javac inconsistency:

        class Foo {
          public static final Bar CONSTANT = new Foo.Bar() {
          };
          public interface Bar {
          }
          public Foo() {
          }
        }
       
       
      Sun's javac will compile this input, while gjc gives an error:
       
      $ kaffe gjc.Main Foo.java
      Foo.java:2: non-static variable this cannot be referenced from a static context
        public static final Bar CONSTANT = new Foo.Bar() {

      Even though javac compiles it, javap crashes on the result:

      Exception in thread "main" java.lang.NullPointerException
              at sun.tools.java.BinaryClass.initInnerClasses(Compiled Code)
              at sun.tools.java.BinaryClass.loadNested(Compiled Code)
              at sun.tools.javap.JavaPEnvironment.loadDefinition(Compiled Code)
              at sun.tools.java.ClassDeclaration.getClassDefinition(Compiled Code)
              at sun.tools.java.Environment.getClassDefinition(Compiled Code)
              at sun.tools.javap.JavaP.displayResults(Compiled Code)
              at sun.tools.javap.JavaP.perform(Compiled Code)
              at sun.tools.javap.JavaP.entry(Compiled Code)
              at sun.tools.javap.JavaP.main(Compiled Code)

            gafter Neal Gafter (Inactive)
            dstoutamsunw David Stoutamire (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: