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

include a more global way of getting at command-line arguments

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      Currently, the only way of getting at the command-line is with the 'args' parameter in the main method. This is fine if that's where you need to use the arguments, but I have code which creates a Properties object populated with properties parsed from the command line. I want to make this class available statically (through something like MyUtils.commandLineProperties), which means that I have to use a static initializer. Since static initializers can't take arguments, and since the command line arguments aren't available globally, I wind up having to do something really awkward, like:
      1. add a static member somewhere such as 'private String[] myUtils.commandLineArgs'
      2. provide a public static setter which ensures the args are only stored once and a getter which ensures the args are available.
      3. add a line to my main class which sets the arguments, and check for the exception thrown
      4. add a line to my static initializer which gets the arguments, and check for the exception thrown

      In addition, this won't work at all if you don't have access to the 'main' method, for example if using an app server.

      JUSTIFICATION :
      1. The other run control stuff (system properties and environment variables) are globally available, so for consistancy so should the command line arguments.
      2. It is currently impossible to access the command line arguments if you don't have access to the main method (such as with an app server).
      3. It would save a lot of unnessary boilerplate on the java programmer's end.
      4. It is extremely easy and straightforward to implement on your end.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      prefferred:

      public static final String System.commandLine

      or:

      public static final String[] System.getArgs()
      (you would have to clone since arrays can't be made immutable)

      or:

      public static final List<String> System.args

      or add the command line to the system properties

      ACTUAL -
      no way to access command-line args
      ###@###.### 2005-05-24 03:42:32 GMT

            psoper Pete Soper (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: