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

java launcher with -jar fails with paths containing colon

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 7u45
    • tools
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      jsailor@karkat-vm-ubuntu1:~/bug$ uname -a
      Linux karkat-vm-ubuntu1 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
      jsailor@karkat-vm-ubuntu1:~/bug$ lsb_release -a
      No LSB modules are available.
      Distributor ID:Ubuntu
        Description:Ubuntu 13.10
        Release:13.10
      Codename:saucy
      jsailor@karkat-vm-ubuntu1:~/bug$

      Also present with java 1.6 on CentOS 6, and 1.7u45 on OSX 10.8

      A DESCRIPTION OF THE PROBLEM :
      When the java command line launcher is run with the "-jar" option and given a path to a jar file which contains a colon, it fails to launch, incorrectly interpreting the file path as a classpath (with >1 entry.)

      While the launcher correctly treats the argument as a file path for purpose of determining the main class (i.e. opening the jar file, reading the manifest, getting the Main-Class), it sets the classpath directly to the value of the argument, which breaks.

      The OpenJDK source contains the following (in hotspot/src/share/tools/launcher/java.c) which would cause the issue:

          /* Override class path if -jar flag was specified */
          if (jarfile != 0) {
              SetClassPath(jarfile);
          }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      jsailor@karkat-vm-ubuntu1:~/bug$ find .
      ./src/MANIFEST.MF
      ./src/Main.java
      ./with:colon/
      ./withoutColon/
      jsailor@karkat-vm-ubuntu1:~/bug$ tail src/*
      ==> src/Main.java <==
      public class Main {
          public static void main(String[] args) {
          System.out.println("ok");
          }
      }

      ==> src/MANIFEST.MF <==
      Main-Class: Main
      jsailor@karkat-vm-ubuntu1:~/bug$ (cd src/ && javac *.java && jar cfm run.jar MANIFEST.MF *.class)
      jsailor@karkat-vm-ubuntu1:~/bug$

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      jsailor@karkat-vm-ubuntu1:~/bug$ cp src/run.jar withoutColon/
      jsailor@karkat-vm-ubuntu1:~/bug$ java -jar withoutColon/run.jar
      ok
      jsailor@karkat-vm-ubuntu1:~/bug$
      ACTUAL -
      jsailor@karkat-vm-ubuntu1:~/bug$ cp src/run.jar with:colon
      jsailor@karkat-vm-ubuntu1:~/bug$ java -jar with:colon/run.jar
      Error: Could not find or load main class Main
      jsailor@karkat-vm-ubuntu1:~/bug$

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Error: Could not find or load main class Main


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See above
      ---------- END SOURCE ----------

            ksrini Kumar Srinivasan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: