JDK-6214916 : -version: argument affects application arguments containing spaces
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-01-06
  • Updated: 2010-12-04
  • Resolved: 2005-06-02
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.
Other JDK 6
5.0u7Fixed 6 b39Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Using the -version:<id> option when running a Java application will split arguments containing spaces.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the simple class added as a test case:

java -version:1.4+ ShowArgs 1 "2 3" 4


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should produce:

1
2 3
4
ACTUAL -
But produces:

1
2
3
4

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class ShowArgs {
	public static void main(String[] args) {
		for (int i = 0; i < args.length; i++)
			System.out.println(args[i]);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not use the -version: option.
###@###.### 2005-1-06 22:45:41 GMT

Comments
EVALUATION The root cause is a bug in Windows spawn/exec implementation. All the Windows POSIX process creation interfaces are implemented as wrappers around the native Windows function CreateProcess(). CreateProcess() takes a single string to specify command line options and arguments, so the POSIX routine wrappers build a single string from the argv[] array and in the process, any quoting information is lost. The solution to this unfortunate sequence of events is to get the original command line, to process it to remove the new multiple JRE options (if any; as was done for argv in the common SelectVersion() routine and finally to pass it directly to the native CreateProcess() Windows process control interface. ###@###.### 2005-2-24 22:41:45 GMT
24-02-2005

SUGGESTED FIX See src/windows/bin/java_md.c - SCCS delta 1.42. Note that due to limitions (ie: bugs) in the MKS shell which is part of the testing environment (jtreg), it was not possible to write a regression test to fully test a couple of quoting edge conditions involving multiple quotes. These have been (and can be) verified by the cutting the nextarg() and unquote() routines from java_md.c into the following little test program. Enhance as you see fit: #include <stdio.h> #include <strings.h> /* string.h on Windows */ /* Insert nextarg() and unquote() here */ int main (int argc, char *argv[]) { int i,j; char* p; char* np; char* strings[] = { "foobar", "\"foo bar\"", "-version:\"1.4+ 1.5+\"", "\"foo \\\" bar \\\" too\"", "\\\\\\\" odd escapes", "\\\\\\\\\" even escapes", "\\f\\a\\ \\t escaped other", (char *)0 }; char* lines[] = { "java -foo app 1 2 3 4", "java -foo app 1 \"2 3\" 4", "java -foo app 1 \"2 \\\" 3\" 4", "java -foo app 1 \"2 \\\\\" 3\" 4", "java -foo app 1 \"2 \\\\\\\" 3\" 4", "java -foo app 1 \"2 \\\\\\\\\" 3\" 4", "java -foo app 1 \\\"2 3\\\" 4", (char *)0 }; i = 0; printf("Unquoting:\n"); while (strings[i] != (char *)0) { printf("in: |%s|\nout: |%s|\n\n", strings[i], unquote(strings[i])); i++; } i = 0; printf("\nTokenizing:\n"); while (lines[i] != (char *)0) { p = strdup(lines[i]); printf("in: |%s|\n", p); while (*p != (char)0) { np = nextarg(p); printf("\ttoken: |%s|\n", p); p = np; } i++; } } ###@###.### 2005-03-18 18:54:28 GMT
24-02-2005