Bug 206178 - [Contributions] null pointer referenced is not caught when registering an action ActionBarAdvisor
Summary: [Contributions] null pointer referenced is not caught when registering an act...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-10-12 14:13 EDT by Amro Al-Akkad CLA
Modified: 2008-05-01 09:45 EDT (History)
4 users (show)

See Also:


Attachments
Patch to check if the IAction is null. (1.13 KB, patch)
2007-10-26 10:46 EDT, Remy Suen CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Amro Al-Akkad CLA 2007-10-12 14:13:25 EDT
If an error in ApplicationActionBarAdivosor-class occurs the application is just terminated, but does not throw an exception on console, even not in debug mode. Example: Save Action. 
When the save action is not created in the RCP's ActionBarAdvisor, but tried to be registered the application is just terminated. 
A possible solution might be: 

 protected void register(IAction action) {
    	try{
        String id = action.getId();
//        Assert.isNotNull(id, "Action must not have null id"); //$NON-NLS-1$
        getActionBarConfigurer().registerGlobalAction(action);
        actions.put(id, action);
    	}
    	catch(NullPointerException e){
			String message = "The to registered action element pointed to null."; //$NON-NLS-1$
			WorkbenchPlugin.log(new Status(IStatus.ERROR, String.valueOf(WorkbenchPlugin.getDefault().getBundle().getBundleId()), message,e ));
		}
    }
Comment 1 Remy Suen CLA 2007-10-12 22:26:56 EDT
I seem to be getting things in my console if I do something like register(null) in my ApplicationActionBarAdvisor's makeActions(IWorkbenchWindow) method on I20071009-2225.

Also, is 206179 essentially a duplicate of this?
Comment 2 Amro Al-Akkad CLA 2007-10-13 06:22:15 EDT
thanks for your quick reply! :)

I don't get anything on my console, but something useful is logged. 
Nevertheless I think my proposal is: 

a.more descriptive to find out what was the cause 

1.(my suggeston's log):
!ENTRY 22 4 0 2007-10-13 11:53:57.093
!MESSAGE The to registered action element pointed to null.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.application.ActionBarAdvisor.register(ActionBarAdvisor.java:190)
	at testsnady.ApplicationActionBarAdvisor.makeActions(ApplicationActionBarAdvisor.java:24)
	at org.eclipse.ui.application.ActionBarAdvisor.fillActionBars(ActionBarAdvisor.java:148)
	at org.eclipse.ui.internal.WorkbenchWindow.fillActionBars(WorkbenchWindow.java:3301)
	...

comparted to:

!ENTRY org.eclipse.ui 4 0 2007-10-13 11:57:02.640
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.application.ActionBarAdvisor.register(ActionBarAdvisor.java:188)
	at testsnady.ApplicationActionBarAdvisor.makeActions(ApplicationActionBarAdvisor.java:24)
	at org.eclipse.ui.application.ActionBarAdvisor.fillActionBars(ActionBarAdvisor.java:147)
	at org.eclipse.ui.internal.WorkbenchWindow.fillActionBars(WorkbenchWindow.java:3301)
	 

b. and further more essential the application is not terminated, only because an action item could not be registerd. Maybe referring to this different opinions exists, but in my opinion that application should only be terminated if an error message is printed to the console. 

Concerning 206179 I I'll comment soon, again. 
Comment 3 Remy Suen CLA 2007-10-13 06:29:53 EDT
(In reply to comment #2)
> I don't get anything on my console, but something useful is logged.

Sorry, I don't understand. Your Eclipse console has nothing but you have things in your target runtime workspace's logs?
Comment 4 Amro Al-Akkad CLA 2007-10-13 06:33:51 EDT
> Sorry, I don't understand. Your Eclipse console has nothing but you have things in your target runtime workspace's logs?
Exactly. Any idea?

Can you please comment 'b.', too. 
Comment 5 Remy Suen CLA 2007-10-13 22:21:14 EDT
(In reply to comment #4)
> > Sorry, I don't understand. Your Eclipse console has nothing but you have things in your target runtime workspace's logs?
> Exactly. Any idea?

Well, as I mentioned, I have stuff in my logs.

> Can you please comment 'b.', too.

If an application terminates and errors are logged, I feel it's perfectly valid for it to terminate. I do not feel that it's necessary to spit output onto the console. Log files are there for a reason. Perhaps someone from the Platform team can comment on this, but this is just my own opinion.
Comment 6 Amro Al-Akkad CLA 2007-10-14 10:28:39 EDT
First of all thanks for your replies. 

In general I agree with you concerning the logging, but referring to the high learning curve for getting familiar with eclipse (plug-in development /) RCP I thought for beginners this might be better. 

So, I keep up to you what is the better way concerning the reported bugs/enhancements!
Comment 7 Remy Suen CLA 2007-10-14 14:58:46 EDT
Can you provide your build ID (Help -> About Eclipse SDK)? Also, can you provide the exact steps to reproduce the behaviour in question? If my application crashes because of an NPE, as far as I can remember, I've always had something in my console even if it is not a full stack trace. So the fact that you have nothing in your logs interests me.
Comment 8 Amro Al-Akkad CLA 2007-10-14 18:43:30 EDT
1) Eclipse SDK, Version: 3.3.1, Build id: M20070921-1145. 

2) Sorry, if I didn't express myself good, but I do get the NPEs in the '.log'-file. I only get neither sth on 'console view' nor on 'cmd line console'. 

3) The procedure is the same as yours, just try to register 'null' or rather an IAction field which references 'null'. Concerning 206179 the procedure is alrieady delivered in the description. 
Comment 9 Remy Suen CLA 2007-10-15 10:26:10 EDT
If you put print statements before you cause your NPE, does it appear in the console?
Comment 10 Amro Al-Akkad CLA 2007-10-15 14:56:06 EDT
Yes, they appear in the console.

Comment 11 Paul Webster CLA 2007-10-23 14:07:14 EDT
If someone wants to submit a patch I'll consider it.

appropriate is check for null and throw an IllegalArgumentException

PW
Comment 12 Remy Suen CLA 2007-10-26 10:46:57 EDT
Created attachment 81267 [details]
Patch to check if the IAction is null.
Comment 13 Paul Webster CLA 2008-04-08 12:52:00 EDT
Released to HEAD >20080408
PW
Comment 14 Paul Webster CLA 2008-05-01 09:45:14 EDT
In I20080501-0100
PW