Re: Command-line arg
- From: Wayne <nospam@xxxxxxxxxxxxxx>
- Date: Fri, 19 Oct 2007 19:34:18 -0400
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
.
- Follow-Ups:
- Re: Command-line arg
- From: Roedy Green
- Re: Command-line arg
- From: Daniel Pitts
- Re: Command-line arg
- From: Mike Schilling
- Re: Command-line arg
- References:
- Command-line arg
- From: joe
- Re: Command-line arg
- From: Wayne
- Re: Command-line arg
- From: Mark Space
- Command-line arg
- Prev by Date: More friends more money,get friends while get paid
- Next by Date: Re: Is there a startup banner class in Java?
- Previous by thread: Re: Command-line arg
- Next by thread: Re: Command-line arg
- Index(es):
Relevant Pages
|