JDK-8296383 : javapath/java.exe strips embedded double quotes from command line arguments
  • Type: Bug
  • Component: install
  • Sub-Component: install
  • Affected Version: 11,17,18,19
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-10-28
  • Updated: 2023-01-12
  • Resolved: 2022-12-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 21
11.0.19-oracleFixed 17.0.7-oracleFixed 21 b02Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10 

java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)

(The same behavior can be observed from Java version 1.8 and above)

A DESCRIPTION OF THE PROBLEM :
When Installing Java 17.0.5, there at least two java.exe installed:

1. C:\Program Files\Java\jdk-17.0.5\bin\java.exe
2. C:\Program Files\Common Files\Oracle\Java\javapath\java.exe

and #2 is the picked up as the java command on the system.

The two java's respond differently to embedded quoted arguments on the command line

#1 keeps the quoted args
#2 strips them

Please also see JDK-8266473 which fixed the outer double quoted arguments case.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a java program to print out the command line args:

public class PrintArgs
{
    public static void main(String [] args)
    {
	for (String arg: args)
	    {
		System.out.println(arg);
	    }
    }
}

Running this using the javapath/java.exe (the numbers represent the depth of the embedded quotes):
"C:\Program Files\Common Files\Oracle\Java\javapath\java.exe" PrintArgs "0\"1\\\"2\\\"1\"0"

gives back

0"1\2\1"0

while running them with java from the jdk directoy, 
"C:\Program Files\Java\jdk-17.0.5\bin\java.exe" PrintArgs "0\"1\\\"2\\\"1\"0"

gives back

0"1\"2\"1"0

i.e. the embedded double quotes are respected.




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the result of calling both java.exe's to be the same and to respect the embedded double quotes in command line arguments.
ACTUAL -
The result differs between the two invocation, and the embedded double quote is dropped from javapath/java.exe

FREQUENCY : always



Comments
[11u-na, 17u-na] Install is not maintained in OpenJDK.
12-01-2023

The issue is similar to https://bugs.openjdk.org/browse/JDK-8266473. We may need to add tstring keepquotes = tstrings::replace(argarg, _T("\\"), _T("\\\\")); at https://orahub.oci.oraclecorp.com/jpg-dev/jdk17/-/blob/0e51c110d3776178b4c1dcf86f299a5ec4af55de/closed/install/src/windows/shimlaunchers/shim.cpp#L53
04-11-2022