Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7020384

RuntimeMXBean.getInputArguments() does not work correctly with spaces

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_23"
      Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
      Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      A DESCRIPTION OF THE PROBLEM :
      When process runs on Windows with arguments that contain spaces (for example, "-Dtitle=12 Monkeys" (in quotes), RuntimeMXBean.getInputArguments() returns two separate strings ('-Dtitle=12' and 'Monkeys').
      Expected is one string.

      This happens because native method
      sun.management.VMManagementImpl.getVmArguments0()
      calls some code defined inside management.cpp that just joins all the strings with spaces in between and returns the data in String format, which is then parsed back into a list by VMManagementImpl.getVmArguments().
      By this time, the information on where the argument boundaries are is lost already.

      The practical type of values that both can contain spaces and are frequently passed in command line are the paths to files.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use test class
      -----------------------------
      import java.util.List;

      public class Test {
          public static void main(String[] args) {
              List<String> allArguments = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments();
              for(String s : allArguments) {
                  System.out.println(s);
              }
              
          }
      }
      ---------------------------

      Run it with
      java "-Dtitle=12 Monkeys" Test
      Observe two parts of the string printed on separate lines

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      RuntimeMXBean.getInputArguments() should return arguments in the form in which they are consumed by the JVM

      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: