This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 196052

Summary: Ability to exit app when wrong CLI options passed in
Product: platform Reporter: Jaroslav Tulach <jtulach>
Component: Launchers&CLIAssignee: Jaroslav Tulach <jtulach>
Status: RESOLVED FIXED    
Severity: normal CC: AngeloD, apireviews, jglick
Priority: P1 Keywords: API_REVIEW_FAST
Version: 7.0   
Hardware: Other   
OS: Linux   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: Implementation and API documentation

Description Jaroslav Tulach 2011-02-27 07:56:18 UTC
The NetBeans IDE continues to start when wrong CLI options are passed in. This is OK, as the only option --open is not essential. However for certain applications on NetBeans it does not make sense to start when options are not provided.

So far one can call LifecycleManager.exit() from the OptionProcessor. However calling this API from middle of startup sequence cannot really bulletproof. I've seen it to leave the layout of windowsystem in very bad shape.

Having nicer API to achieve the same would be desirable.
Comment 1 Jaroslav Tulach 2011-02-27 08:32:48 UTC
Created attachment 106488 [details]
Implementation and API documentation
Comment 2 Jaroslav Tulach 2011-02-27 08:34:33 UTC
I'd like to get this change into 7.0. That means to integrate by Tuesday. Can I find few reviewers that could approve/verify the change and let me integrate without a week of waiting time?
Comment 3 Jesse Glick 2011-03-03 00:29:20 UTC
"...when some CLI cannot..." - missing "option" I guess.


[JG01] This change seems very magical and relies on an atypical use of a special bundle key. Why does it need to be so complicated? Just define a constant in CommandException:

  public static final int FORCE_EXIT = -1; // or whatever

If some processor throws a CE with this exit code, terminate the app rather than just issuing a warning.

(I find it surprising that the exit code param to CE does not already terminate the app; its Javadoc does say "the value to be usually send to as a return value to System.exit".)
Comment 4 Jaroslav Tulach 2011-03-03 21:16:43 UTC
> relies on an atypical use of a special bundle key

C'mon. Using bundles to differentiate the behavior between different applications build on top of Netbeans Platform is normal. Window system does that. If the behavior of the IDE and other applications shall be different, Bundle is a perfect way to specify that.
 
> (I find it surprising that the exit code param to CE does not already terminate
> the app; its Javadoc does say "the value to be usually send to as a return
> value to System.exit".)

Right, the error code shall terminate the app I can change the default in the platform. Shall the NetBeans IDE exit if someone passes non-existent file to --open too?

> . Why does it need to be so complicated? Just define a
> constant in CommandException: public static final int FORCE_EXIT = -1; 

OK, this would be compatible extension with a bunch of freedom for OptionProcessor writers. If none of the above approaches is acceptable, then I can implement this one.
Comment 5 Jesse Glick 2011-03-03 21:40:36 UTC
(In reply to comment #4)
> this would be compatible extension with a bunch of freedom for
> OptionProcessor writers.

And much more discoverable than the current proposal, which forces you to go looking for a magic bundle value hidden in an arch document which is not even in the public API set.
Comment 6 Jaroslav Tulach 2011-03-04 14:32:20 UTC
I guess I try something else: I exit the system whenever a processor yields non-zero value. I keep the branding API for those who want to keep current behavior.
Comment 7 Jesse Glick 2011-03-04 15:49:03 UTC
(In reply to comment #6)
> I exit the system whenever a processor yields non-zero value.

Seems reasonable default behavior, seeing as this is what the documentation already implies. After all, if there is some problem but you _don't_ want your processor to exit, you can simply print a warning message but return 0; is there any other reason to return a nonzero value? (To stop parsing of subsequent args perhaps?)
Comment 8 Jaroslav Tulach 2011-05-11 13:12:49 UTC
OK, I change the code to exit the application if non-zero code is returned.
Comment 9 Jaroslav Tulach 2011-05-13 17:49:02 UTC
ergonomics#df53730d2efa
Comment 10 Quality Engineering 2011-05-15 08:37:44 UTC
Integrated into 'main-golden', will be available in build *201105150400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/df53730d2efa
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #196052: Exit when command line options cannot be parsed