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

JVM silently expands command line arguments before invoking "main()"

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8u5
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_8

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      AFAIK any Java version from 1.0 up to and including 1.8

      FULL OS VERSION :
      Windows 8.1 Professional, AFAIK all other versions of MS Windows.
      Does NOT occur on Linux JVMs!

      A DESCRIPTION OF THE PROBLEM :
      The line arguments of the JVM are suspect to an undocumented expansion:
      Any argument that matches one or more files is replaced with the names of the files.

      Notice that this is NOT the expansion that many shells do BEFORE executing "java.exe"; instead, the "java.exe" ITSELF does it before invoking "main()"!

      This behavior is problematic when you want to pass a LITERAL "*", "?" or "[" to a Java program on the command line, e.g.:

            $ java.exe Calc 7 "*" 13
            $ java.exe Find . -name "*.java"

      So far, I could not find a workaround.

      The behavior is very confusing to the user, and forces programmers to change their command line syntax only to make it possible to run their programs on a WINDOWS JVM. Thus I consider this behavior as a bug

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test program with
      java.exe -cp target/classes foo.Main a "*" b

      Verify that the command line arguments of the running JVM with SYSINTERNALS PROCEXP:
      "C:\Program Files\Java\jdk1.8.0_05\jre\bin\java.exe" -cp target/classes foo.Main a * b


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected output:
      args[0]= "a"
      args[1]= "*"
      args[2]= "b"
      Done

      Actual output:
      args[0]= "a"
      args[1]= ".classpath"
      args[2]= ".project"
      args[3]= ".settings"
      args[4]= "pom.xml"
      args[5]= "src"
      args[6]= "target"
      args[7]= "b"
      Done
      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package foo;

      public class Main {

      public static void main(String[] args) throws InterruptedException {
      for (int i = 0; i < args.length; i++) {
      System.out.println("args[" + i + "]= \"" + args[i] + "\"");
      }
      Thread.sleep(5000);
      System.out.println("Done");
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Unfortunately I could not find a workaround.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aroy Abhijit Roy (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: