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

Broken --class-path handling in shebang files

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Java:

      java version "11.0.7" 2020-04-14 LTS
      Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)

      Linux:
      Linux e6540 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Executing a shebang file with --class-path argument with Oracle JDK 11.0.7 leads to an error.
      Executing a shebang file with --class-path argument with Oracle JDK 14.0.1 works as expected.

      See examples below.

      #!/usr/bin/java --source 11 --class-path include.jar

      public class ShebangExample {
          public static void main(String[] args){
              System.out.println("Works!");
          }
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Executing a shebang file with --class-path argument with Oracle JDK 11.0.7 leads to an error

      michael@e6540:/tmp/tmp.XXnDbSFhzk$ ls -l
      total 144
      -rwxr-xr-x 1 michael michael 194 Apr 14 22:58 example-11.sh
      -rwxr-xr-x 1 michael michael 194 Apr 14 22:59 example-14.sh
      -rw-r--r-- 1 michael michael 136837 Apr 14 22:59 include.jar
      michael@e6540:/tmp/tmp.XXnDbSFhzk$ cat example-11.sh
      #!/usr/lib/jvm/jdk-11.0.7/bin/java --source 11 --class-path include.jar

      public class ShebangExample {
          public static void main(String[] args){
              System.out.println("Works!");
          }
      }

      michael@e6540:/tmp/tmp.XXnDbSFhzk$ ./example-11.sh
      Error: Could not find or load main class ..example-11.sh
      Caused by: java.lang.ClassNotFoundException: //example-11/sh
      michael@e6540:/tmp/tmp.XXnDbSFhzk$

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Executing a shebang file with --class-path argument with Oracle JDK 14.0.1 works as expected

      michael@e6540:/tmp/tmp.XXnDbSFhzk$ ls -l
      total 144
      -rwxr-xr-x 1 michael michael 194 Apr 14 22:58 example-11.sh
      -rwxr-xr-x 1 michael michael 194 Apr 14 23:02 example-14.sh
      -rw-r--r-- 1 michael michael 136837 Apr 14 22:59 include.jar
      michael@e6540:/tmp/tmp.XXnDbSFhzk$ cat ./example-14.sh
      #!/usr/lib/jvm/jdk-14.0.1/bin/java --source 11 --class-path include.jar

      public class ShebangExample {
          public static void main(String[] args){
              System.out.println("Works!");
          }
      }

      michael@e6540:/tmp/tmp.XXnDbSFhzk$ ./example-14.sh
      Works!
      michael@e6540:/tmp/tmp.XXnDbSFhzk$
      ACTUAL -
      Error: Could not find or load main class ..example-11.sh
      Caused by: java.lang.ClassNotFoundException: //example-11/sh

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: