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

implicit use of this before super() should be disallowed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 7
    • 1.4.0
    • specification
    • rc
    • generic
    • solaris_8
    • Verified

    Description

      javac fails to compile the following program, even though it violates
      no rules in the spec. I suspect his should be disallowed by the
      specification, as the constructor of Up could call a member method of Fake
      and observe the state of Fake before Fake's superclass constructor has been
      called. If we intend this to be illegal, the spec needs to clearly
      disallow it.



      frog:~/workspaces/test/4626788 $ cat -n T.java
           1 class Top {
           2 Top(Object o) {}
           3 }
           4
           5 class Bottom {
           6 int x = 2;
           7
           8 class Fake extends Top {
           9 class Up {
          10 Up() { int y = x; }
          11 }
          12
          13 Fake() {
          14 super(new Up() {});
          15 }
          16 }
          17 }
      frog:~/workspaces/test/4626788 $ newjavac -target 1.4 T.java
      T.java:14: no enclosing instance of type Bottom.Fake is in scope
                  super(new Up() {});
                                 ^
      1 error
      frog:~/workspaces/test/4626788 $ cat -n U.java
           1 class Top {
           2 Top(Object o) {}
           3 }
           4
           5 class Bottom {
           6 int x = 2;
           7
           8 class Fake extends Top {
           9 class Up {
          10 Up() { int y = x; }
          11 }
          12
          13 Fake() {
          14 super(new Up());
          15 }
          16 }
          17 }
      frog:~/workspaces/test/4626788 $ newjavac -target 1.4 U.java
      U.java:14: cannot reference this before supertype constructor has been called
                  super(new Up());
                        ^
      1 error
      frog:~/workspaces/test/4626788 $

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: