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

classpath that begins with separator: behavior disagrees with java

    XMLWordPrintable

Details

    • b26
    • generic, x86, sparc
    • other, solaris_9, windows_nt

    Description

      This bug can be detected under Windows as well as under Solaris, probably under each Java environment, because javac is written in Java.

      Problem:
      If Classpath starts with the Classpath delimiter character (":" under Unix, ";" under Windows), javac will search in the root directory for packages/classes
      but the interpreter java doesn't (java is searching in the current directory).
      Furthermore if Classpath contains the Classpath delimiter character twice ("::" under Unix, ";;" under Windows, javac will search in the root directory for packages/classes but the interpreter java doesn't.
      With respect to avoid compile problems, javac should ignore leading classpath delimiters and javac should ignore double classpath delimiters in the classpath settings.

      Prepare the testcase
      --------------------
      1. Make a folder called test in the root directory
      % mkdir /test
      2. Store the following source code in /test
        package test;
        public class Test{

          public int getS(int n){
            return n;
          }
        }
      3. Compile the Test class in /test
      % cd /
      % javac -classpath . test/Test.java

      4. Create a directory in any subfolder, e. g. your homedirectory
      % mkdir -p ~/testcase/test

      5. Store a file called Test.java to ~/testcase/test
        package test;
        public class Test {
           public void getS() {}
        }

      6. Compile the Test.java
      % cd ~/testcase
      % javac -classpath . test/Test.java

      7. Create a file Main.java in ~/testcase
         import test.*;
         public class Main {

         public static void main(String[] args) {
           new Main();
         }
         public Main() {
           sM();
         }
         public void sM(){
           Test t = new Test();
           t.getS();
         }
       }

      Please note, that Main.java is using a class called Test.class. Main.java is only compatible with the Test.class version in ~/testcase/test, Main.java is incompatible with Test.class version in /test

      How to reproduce
      ----------------
      1.a Compile Main.java
      % cd ~/testcase
      % javac -classpath . Main.java
      You should not get any errors.

      1.b Run Main.java
      % java -classpath . Main
      You should net get any errors.

      2.a Compile Main.java with wrong class
      % javac -classpath /:. Main.java
      Main.java:15: getS(int) in test.Test cannot be applied to ()
           t.getS();
            ^
      1 error

      This is what we expected, because the /test/Test.class will be found first.
      Use -verbose mode to see which classes are loaded.

      2.b Run Main with wrong classes
      % java -classpath /:. Main
      Exception in thread "main" java.lang.NoSuchMethodError: test.Test.getS()V
              at Main.sM(Main.java:15)
              at Main.<init>(Main.java:10)
              at Main.main(Main.java:6)

      This is what we expected, because the /test/Test.class will be found first.

      3.a Compile Main.java with leading colon in classpath
      % javac -classpath :. Main.java
      Main.java:15: getS(int) in test.Test cannot be applied to ()
           t.getS();
            ^
      1 error

      Oopps, we get an error here? That means, the Test.class in /test will be used and not the Test.class in ~/testcase/test

      3.b Run Main with leading colon in classpath
      java -classpath :. Main
      We didn't get any error here. That means, the Test.class in ~/testcase/test will be used and not the Test.class in /test

      ==> java and javac are handling the classpath settings in a different way,
      javac is searching for classes in / if the classpath starts with Classpath delimiter (":" under Unix, ";" under Windows).
      java is searching for classes in "." if the classpath starts with Classpath
      delimiter.
      See also http://developer.java.sun.com/developer/bugParade/bugs/4515984.html

      4.a Compile Main.java with a double colon in classpath
      javac -classpath "something::." Main.java
      Main.java:15: getS(int) in test.Test cannot be applied to ()
           t.getS();
            ^
      1 error

      4.b Run Main with a double colon in classpath
      java -classpath "something::." Main
      We didn't get any error here. That means, the Test.class in ~/testcase/test will be used and not the Test.class in /test

      ==> java and javac are handling the classpath settings in a different way,
      javac is searching for classes in / if the classpath contains double Classpath delimiters ("::" under Unix, ";;" under Windows).

      ---
      Please fix in upcoming 1.4.2 as well. SAP will migrate to this release as soon
      as software is available.

      ###@###.### 2003-01-29

      Attachments

        Issue Links

          Activity

            People

              martin Martin Buchholz
              jloefflm Johann Löfflmann (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: