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

subpackage and class with the same name

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.0
    • tools
    • sparc
    • solaris_2.5

    Description



      Name: ngC57085 Date: 02/11/98



      Java compilers jdk1.2beta3E and jdk1.2beta3F permit subpackage and class
      with the same name.
      Next two files are compiled without error message.

      ------------------- pkgs00603 -----------------------
      package javasoft.sqe.tests.lang.pkgs006.pkgs00603;

      import java.io.PrintStream;
      import javasoft.sqe.tests.lang.pkgs006.pkgs00603.pkgs00603a.*;

      public class pkgs00603 {
        public static void main(String argv[]) {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
           if ( pkgs00603a.sum (1,2) != pkgs00603c.plus (1,2) ) {
              out.println("failed");
              return 2/*STATUS_FAILED*/;
           }
           return 0/*STATUS_PASSED*/;
        }
      }

      class pkgs00603a {
        public static int sum(int p1, int p2) {
           return p1+p2;
        }
      }
      -----------------------------------------------------
      ------------------- pkgs00603c ----------------------
      package javasoft.sqe.tests.lang.pkgs006.pkgs00603.pkgs00603a;

      public class pkgs00603c {
        public static int plus(int p1, int p2) {
           return p1+p2;
        }
      }
      -----------------------------------------------------
      > javac -d . pkgs00603c.java pkgs00603.java
      > java -verify javasoft.sqe.tests.lang.pkgs006.pkgs00603.pkgs00603
      > echo $status
      95

      Hook 5(hook5): test




      Name: ngC57085 Date: 02/24/98


      New addition to bug description.
      Consider two compilation units which may be compiled in arbitrary order such
      as the followings:

      ------------------- pkgs00604 -----------------------
      package javasoft.sqe.tests.lang.pkgs006.pkgs00604;

      import java.io.PrintStream;
      import javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604a.*;

      public class pkgs00604 {
        public static void main(String argv[]) {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
           if ( pkgs00604a.sum (1,2) != 3 ) {
              out.println("failed");
              return 2/*STATUS_FAILED*/;
           }
           return 0/*STATUS_PASSED*/;
        }
      }
      class pkgs00604a {
        public static int sum(int p1, int p2) {
           return p1+p2;
        }
      }
      -----------------------------------------------------
      ------------------- pkgs00604c ----------------------
      package javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604a;
       
      public class pkgs00604c {
        public static int plus(int p1, int p2) {
           return p1+p2;
        }
      }
      -----------------------------------------------------
      4 cases may be used to compile this test.
      Just one case is completed by error message. Three other comilations
      are successful, althrough a package may not contain a type declaration
      and a subpackage of the same name.

           // 1 case
      > javac -d . pkgs00604c.java
      > javac -d . pkgs00604.java
      pkgs00604.java:7: Ambiguous name: javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604a is both a class and a package.
      import javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604a.*;
             ^
      1 error
      >
           // 2 case
      > javac -d . pkgs00604.java
      > javac -d . pkgs00604c.java
      > java -verify javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604
      > echo $status
      95
      >
           // 3 case
      > javac -d . pkgs00604.java pkgs00604c.java
      > java -verify javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604
      > echo $status
      95
      >
           // 4 case
      > javac -d . pkgs00604c.java pkgs00604.java
      > java -verify javasoft.sqe.tests.lang.pkgs006.pkgs00604.pkgs00604
      > echo $status
      95
      >

      jdk1.2beta3 and jdk1.1.6 show the same results.
      Could you please to reevaluate this bug.

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

      Attachments

        Issue Links

          Activity

            People

              tturnidgsunw Todd Turnidge (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: