JDK-8266473 : javapath/java.exe strips double quotes from command line args
  • Type: Bug
  • Component: install
  • Sub-Component: install
  • Affected Version: 11,15,16,17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-05-02
  • Updated: 2021-07-15
  • Resolved: 2021-06-21
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
11.0.13-oracleFixed
Description
A DESCRIPTION OF THE PROBLEM :
When installing Java 16.0.1 at least two java.exe files are installed. On my machine:

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

And #2 is the one linked to the `java` command on the system.

These two java.exe behave differently with respect to double quoted command line arguments.

#1 Keeps the double quotes
#2 Strips the double quotes


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Here's a reproduction:

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

Running this using the installed java (which uses #2 above):

    PS C:\Program Files\Java\jdk-16.0.1\bin> java PrintArgs '\"bar\"'
    bar


Running it using #1:

    PS C:\Program Files\Java\jdk-16.0.1\bin> .\java.exe PrintArgs '\"bar\"'
    "bar"



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should print "bar" (with the double quotes intact).
ACTUAL -
Prints bar (double quotes stripped).

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

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have found no workaround what so ever. I'd be super happy to know of one.

FREQUENCY : always



Comments
Additional Information from submitter: =========================== I was requested to provide some more context about my remark that the workaround was a bit clunky. Does the following make sense? I run into this issue because a super important feature in a VS Code Extension I maintain relies on that it can start a java program with double quotes in the arguments. For me the workaround will probably suffice. I haven't implemented it yet, but can see no reason it wouldn't. However, since the workaround relies on a mechanism that is not present pre JDK9, I will have to first check java version and then start the java process in two different ways. I am hoping someone will figure out a workaround where I can keep my code a bit less concerned with which java version is being used.
10-05-2021

Additional Information from submitter: =========================== A workaround is to provide the arguments via a file. PS C:\Users\Public\javaargs> type args.txt -Dfoo.bar=xs PrintArgs 1 2 3 "\"dude\"" PS C:\Users\Public\javaargs> java '@args.txt' 1 2 3 "dude" PS C:\Users\Public\javaargs> java -version java version "16.0.1" 2021-04-20 Java(TM) SE Runtime Environment (build 16.0.1+9-24) Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing) PS C:\Users\Public\javaargs> get-command java CommandType Name Version Source ----------- ---- ------- ------ Application java.exe 16.0.1.0 C:\Program Files\Common Files\Oracle\Java\javapath\java.exe PS C:\Users\Public\javaargs> Only works with JDK9+ so it is not the most convenient workaround.
05-05-2021

The issue is reproducible with JDK 11 too. After installing JDK binaries, JDK is installed at two different locations 1. C:\Program Files\Java\jdk-16.0.1\bin\java.exe 2. C:\Program Files\Common Files\Oracle\Java\javapath\java.exe 2nd one being the link to the `java` command on the system. However both behave differently when passed with a command line argument. Run the reproducer with- .\java.exe PrintArgs '\"bar\"' #1 gives "bar" #2 gives bar
04-05-2021