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

javac allows access to interface members inherited protected from Object

    XMLWordPrintable

Details

    • hopper
    • generic
    • generic, solaris_7, solaris_8
    • Verified

    Description

      From the Java Spec Report mailing list:

      Perhaps JLS 9.2 is correct after all, that interfaces do NOT extend
      Object from the language point of view (even if they do so from the VM
      point of view), and that therefore interfaces do not have clone() or
      finalize(). Both jikes and javac compile this example, but the
      resulting .class file from either compiler causes the VM to throw a
      VerifyError. But if the two compilers were to take JLS 9.2 at face
      value, rather than implementing the suggestions of the spec report, this
      would be a compile-time error.

      $ cat Blah.java
      class Blah {
        public static void main(String[] args) {
          I.Inner.bar(new I(){});
        }
      }
      interface I {
        class Inner {
          static void bar(I i) {
            try {
              // An inner class has access to any protected members, but
              // according to JLS 9.2, I has no protected members, so this
              // reference to finalize should not compile.
              i.finalize();
            } catch (Throwable t) {
            }
          }
        }
      }
      $ javac Blah.java
      $ java Blah
      Exception in thread "main" java.lang.VerifyError: (class: I$Inner,
      method: bar signature: (LI;)V) Bad access to protected data
              at Blah.main(Blah.java:3)

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              gafter Neal Gafter
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: