Re: Command-line arg



Mark Space wrote:
It is theoretically possible for main() to be called with a null
argument. You may wish to check for this also or risk throwing a
NullPointer exception.

Nope. Section 12.1.4 of the JLS:
<quote>
The method main must be declared public, static, and void. It must
accept a single argument that is an array of strings. This method
can be declared as either

public static void main(String[] args)

or

public static void main(String... args)
</quote>

And Section 2.16.1 of the JVM spec:
<quote>
A Java Virtual Machine starts execution by invoking the
method main of some specified class, passing it a single
argument, which is an array of Strings. ...
</quote>

I think the only legal but not stated variation is declaring
main as:
public static void main ( String args[] )

So, if your JVM is capable of passing a null to main,
it is not a legal JVM. Invoking args.length in main
can not throw a NullPointerException in any valid JRE.

Have you ever run across a JVM that passed a NULL to main?
I've never tested any JVMs for that, but if there are
popular JVMs that do this I guess such a test would be
worthwhile.

-Wayne
.



Relevant Pages

  • Re: Command-line arg
    ... NullPointer exception. ... public static void main ... So, if your JVM is capable of passing a null to main, ...
    (comp.lang.java.programmer)
  • java assembler?? for Javap utility??
    ... public static void main; ... to the JVM how can i run the "Hello" program through JVM by giving the ... above byte code instructions "which was gained by using the javap ... If somebodyt know about a java tool I can use to assemble the code wich ...
    (comp.lang.java.programmer)
  • java assembler?? for Javap utility??
    ... public static void main; ... to the JVM how can i run the "Hello" program through JVM by giving the ... above byte code instructions "which was gained by using the javap ... If somebodyt know about a java tool I can use to assemble the code wich ...
    (comp.lang.java.help)
  • java assembler?? for Javap utility??
    ... public static void main; ... to the JVM how can i run the "Hello" program through JVM by giving the ... above byte code instructions "which was gained by using the javap ... If somebodyt know about a java tool I can use to assemble the code wich ...
    (comp.lang.java.softwaretools)
  • JVM Memory leak after interrupting threads??
    ... Why is the JVM not reclaiming the ... See below for simple test program ... public static void main ...
    (comp.lang.java.programmer)