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.
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.
- relates to
-
JDK-8131680 JVM silently expands command line arguments before invoking "main()"
-
- Closed
-
-
JDK-8158359 bug JDK-8131329 incorrectly labeled as NOT AN ISSUE
-
- Closed
-