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

Inner class user of super causes a NoSuchMethodException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • tools
    • sparc
    • solaris_8

      ces

      Name: boT120536 Date: 03/20/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      When a sub class' inner class calls super, the virtual machine throws a
      NoSuchMethodException. Here's the scenario.

      =================== In file A.java =====================
      public class A {
          pubilc void init() {
              System.out.println("I'm here");
          }
      }

      =================== In file B.java =====================
      public class B extends A {
          private Y y;

          public B() {
              y = new Y();
          }

          protected interface X {
              public void init();
          }

          protected class Y implements X {
              public void init() {
                  B.super.init();
              }
          }

          public void init() {
              y.init();
          }

          public static void main(String[] args) {
              B me = new B();
              me.init();
          }
      }

      =================
      Then compile with:
      javac -target 1.3 A.java B.java

      Then attempt to run with:
      java B

      You will get:
      Exception in thread "main" java.lang.NoSuchMethodError
              at B$Y.init(B.java:14)
              at B.init(B.java:19)
              at B.main(B.java:25)

      javac for 1.3 will compile this without any complaints. java will then throw a
      NoSuchMethodException when it is run and B.one() is called
      (Review ID: 118920)
      ======================================================================

            gafter Neal Gafter
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: