JDK-6459832 : RuntimeMXBean.getInputArguments() doesn't handle arguments with spaces properly
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-08-14
  • Updated: 2014-02-27
  • Resolved: 2011-03-08
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 7
7 b05Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

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

A DESCRIPTION OF THE PROBLEM :
This routine isn't properly returning arguments with spaces in them. This is a problem for us when trying to parse -javaagent flags with spaces for file paths.





STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
>javac -target 1.5 EchoArgs.java

>java -D"value=one two three" EchoArgs

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
-Dvalue=one two three
one two three
ACTUAL -
-Dvalue=one
two
three
one two three

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class EchoArgs {
    public static void main(String args[]) {
        for (String str: java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()) {
            System.out.println(str);
        }
        System.out.println(System.getProperty("value"));
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
assume that arguments start with a - and hope that no other values do (i.e., there isn't anything reliable)

Comments
SUGGESTED FIX HS now returns an array of VM arguments instead of a string concatenating all arguments. Also changed SDK to use the new HS entry point.
05-12-2006

EVALUATION The VM concatenates all arguments into one string to pass to java.lang.management assuming whitespace is the separator which is incorrect. Will fix it in JDK7.
03-11-2006