Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 230549

Summary: Ex;tensionPointEnabler getPluginModelForProject throws NPE
Product: z_Archived Reporter: Stan Sutton <suttons>
Component: IMPAssignee: Robert M. Fuhrer <rfuhrer>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: jurgen.vinju, pcharles, rfuhrer, suttons
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Stan Sutton CLA 2008-05-06 18:15:20 EDT
In ExtensionPointEnabler.getPluginModelForProject(..) a NullPointerException is
thrown (at least some of the time) when checking the workspace plugins for one
that matches a given project.  This terminates the method, with the result that
the plugin model for the given project will not have been found.

The method is called when adding extensions for new language services to a
project.  Code generation still proceeds correctly, but the NPE means that the
plugin model for the project is not available for updating to reflect the new
extension.
Comment 1 Stan Sutton CLA 2008-05-06 18:15:23 EDT
The method contained a loop, in which the workspace models were iteratively
checked for one (presumably a project plugin model) with an ID that matched the
name of the given project:

   private static IPluginModel getPluginModelForProject(final IProject project) {
	PluginModelManager pmm = PDECore.getDefault().getModelManager();
	IPluginModelBase[] wsPlugins= pmm.getWorkspaceModels();

	if (wsPlugins.length == 0) { ... return null; }

	for(int i= 0; i < wsPlugins.length; i++) {
	    IPluginModelBase wsPlugin= wsPlugins[i];    
	    if (wsPlugin.getPluginBase().getId().equals(project.getName())) {
	        return (IPluginModel) wsPlugin;
	    }
	}
	ErrorHandler.reportError("Could not find plugin for project " + 
           project.getName(), true);
	return null;
    }

It seems that the set of workspace models also includes a workspace plugin
model, which (at least in the case of my runtime workbench) has a null ID.  That
lead to the NPE.  Since the workspace model happened to be the second model
checked, that meant that most project plugin models could not be found.

I had not seen this problem before, and I'm not sure whether it would arise only
in a runtime workbench, whether it relates to some other change that has been
made, or whether it's simply a matter of chance.

The solution that I've implemented is to check for nulls in the various elements
that go into the test against the project name and to continue the iteration if
any of them is null.  Regardless of why the problem has turned up now, this
seems to be a reasonable thing to do.
Comment 2 Robert M. Fuhrer CLA 2008-05-06 18:15:27 EDT
This is perhaps the nastiest of bugs in the SAFARI "front end", and *seems* to
be due to some strange and somewhat intermittent caching done by the PDE.

By the time the code in question is reached (if my memory serves me), it should
already have been established that the project is a plugin project, and moreover
is open, so I believe it's safe to assume that the PDE should have or be able to
create a "workspace plugin model" (or thereabouts).

Obviously, either there's a bug in the PDE (which is my guess), or the PDE was
never intended to provide this guarantee (which would be somewhat shocking, or
at least counter-intuitive).
Comment 3 Robert M. Fuhrer CLA 2008-05-08 16:16:31 EDT
<gratuitous comment for change of status>