-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8u45
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
FULL OS VERSION :
Windows 7 Professional, 64 bit, Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
According to the documentation of the JAVA tool, the command line arguments following the class name are supposed to be mapped to the "args" parameter of the MAIN method. However if the characters "\*\" (backslash, asterisk, backslash) occur in an argument, then the argument is modified in a very strange way:
It appears that in the character sequence
'\' '*' { '\' '*' }
, the nth backslash is replaced with n backslashes.
This behavior causes subtle problems e.g. if you write a GREP utility in Java and use it to find DOC comments in a java source file, like this:
$ java com.acme.Grep '/\*\*' *.java
$
Even though "/\*\*" is the correct regular expression to match "/**" (the beginning of a DOC comment), no matches will be found because due to the described bug the command line argument "/\*\*" is silently changed to "/\*\\*", which no longer matches "/**".
The bug is reproducible with the following WINDOWS JREs:
jre1.7.0_80
jre1.7.0_80 (32 bit)
jre1.8.0_45
jre1.8.0_45 (32 bit)
The bug does NOT occur with the following WINDOWS JREs:
jre1.5.0_17 (32 bit)
jre1.6.0_42
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the "source code for an executable test case", below.
Run it as follows:
--------------------
$ java.exe foo.Echo 'aaa\*\*\*\*\*\a\*\*\*bbb'
aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
$
--------------------
The purpose of the single quotes is to prevent the command shell (BASH in this case) to process the backslashes before running java.exe.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected program output:
aaa\*\*\*\*\*\a\*\*\*bbb
Actual program output:
aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package foo;
public class Echo {
public static void main(String[] args) {
for (String arg : args) {
System.out.println(arg);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None known.
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
FULL OS VERSION :
Windows 7 Professional, 64 bit, Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
According to the documentation of the JAVA tool, the command line arguments following the class name are supposed to be mapped to the "args" parameter of the MAIN method. However if the characters "\*\" (backslash, asterisk, backslash) occur in an argument, then the argument is modified in a very strange way:
It appears that in the character sequence
'\' '*' { '\' '*' }
, the nth backslash is replaced with n backslashes.
This behavior causes subtle problems e.g. if you write a GREP utility in Java and use it to find DOC comments in a java source file, like this:
$ java com.acme.Grep '/\*\*' *.java
$
Even though "/\*\*" is the correct regular expression to match "/**" (the beginning of a DOC comment), no matches will be found because due to the described bug the command line argument "/\*\*" is silently changed to "/\*\\*", which no longer matches "/**".
The bug is reproducible with the following WINDOWS JREs:
jre1.7.0_80
jre1.7.0_80 (32 bit)
jre1.8.0_45
jre1.8.0_45 (32 bit)
The bug does NOT occur with the following WINDOWS JREs:
jre1.5.0_17 (32 bit)
jre1.6.0_42
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the "source code for an executable test case", below.
Run it as follows:
--------------------
$ java.exe foo.Echo 'aaa\*\*\*\*\*\a\*\*\*bbb'
aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
$
--------------------
The purpose of the single quotes is to prevent the command shell (BASH in this case) to process the backslashes before running java.exe.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected program output:
aaa\*\*\*\*\*\a\*\*\*bbb
Actual program output:
aaa\*\\*\\\*\\\\*\\\\\*\\\\\\a\*\\*\\\*bbb
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package foo;
public class Echo {
public static void main(String[] args) {
for (String arg : args) {
System.out.println(arg);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None known.
- duplicates
-
JDK-8143640 Showing incorrect result while passing specific argument in the Java launcher tools
- Closed