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

Illegal access to constructor along superclass chain permitted

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: vsC45997 Date: 12/03/96


      The section "13.4.12 Method and Constructor Declarations" of The JLS contains the following:

      "Adding one or more constructor declarations to the source code of such
      a class will prevent this default constructor from being supplied
      automatically, effectively deleting a constructor"

      And the section "8.6.7 Default Constructor" of The JLS contains the following:

      "If a class contains no constructor declarations, then a default
      constructor that takes no parameters is automatically provided:
       
           If the class being declared is the primordial class Object,
           then the default constructor has an empty body.

           Otherwise, the default constructor takes no parameters and simply
           invokes the superclass constructor with no arguments."
       

      The current 1.1 compiler provides illegal access to the default
      constructor of a superclass on the test below.

      The test consist of two files.

      // FILE: binc02601.java
      package javasoft.sqe.tests.lang.binc026.binc02601;
      import java.io.PrintStream;

      class Hyper {
        int f;
        Hyper() { f = 4;}
      }

      class Super extends Hyper {
      }

      public class binc02601 extends Super {
        public static void main(String argv[])
        {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
          try {
            Super x = new Super();
            out.println (x.f);
          }
          catch (NoSuchMethodError e) {
            out.println (e);
            return 0;
          }
          out.println ("failed");
          return 2;
        }
      }
          
         
          
      // FILE: binc02601a.java
      package javasoft.sqe.tests.lang.binc026.binc02601;

      class Super extends Hyper {
        Super(int i) { f = 4+i;}
      }

      After separate compilation and execution with -verify option we have
      on 1.0.2 compiler:
      javac -d . binc02601.java
      javac -d . binc02601a.java
      java -verify javasoft.sqe.tests.lang.binc026.binc02601.binc02601
      java.lang.NoSuchMethodError: javasoft.sqe.tests.lang.binc026.binc02601.Super: method <init>()V not found

      But on 1.1 we have the following:
      jdk_1.1/bin/java -verify javasoft.sqe.tests.lang.binc026.binc02601.binc02601
      4
      failed


      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            nsaraiyasunw Nakul Saraiya (Inactive)
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: