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

Bug 313214

Summary: NPE in org.eclipse.wst.common.componentcore.internal.resources.VirtualContainer.findMember(VirtualContainer.java:80)
Product: [WebTools] WTP Common Tools Reporter: Jason Sholl <jsholl>
Component: wst.commonAssignee: Jason Sholl <jsholl>
Status: RESOLVED FIXED QA Contact: Carl Anderson <ccc>
Severity: normal    
Priority: P3 CC: ccc, david_williams, stryker
Version: 3.2Flags: david_williams: pmc_approved+
stryker: pmc_approved? (raghunathan.srinivasan)
stryker: pmc_approved? (naci.dai)
stryker: pmc_approved? (deboer)
stryker: pmc_approved? (neil.hauge)
stryker: pmc_approved? (kaloyan)
ccc: review+
Target Milestone: 3.2 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Bug Depends on: 313209    
Bug Blocks:    
Attachments:
Description Flags
patch none

Description Jason Sholl CLA 2010-05-17 14:22:13 EDT
+++ This bug was initially created as a clone of Bug #313209 +++

An adopter product has observed the following NPE which blows up the stack.  In theory, a NPE such as this should never occur because a StructureEdit should never be null for a VirtualContainer.  However, considering the complexities of eclipse resource notification firings, and the fact that this can not be reliably reproduced, it would be better to guard against this NPE than letting it blow up the stack.

!ENTRY org.eclipse.core.resources 4 2 2010-02-22 13:50:32.289
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.wst.common.componentcore.internal.resources.VirtualContainer.findMember(VirtualContainer.java:80)
	at org.eclipse.wst.common.componentcore.internal.resources.VirtualContainer.findMember(VirtualContainer.java:71)
	at org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities.findFile(ComponentUtilities.java:121)
	at org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities.getManifestFile(J2EEProjectUtilities.java:246)
	at org.eclipse.jst.j2ee.internal.common.J2EEDependencyListener.visit(J2EEDependencyListener.java:122)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:68)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:79)
	at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:48)
	at org.eclipse.jst.j2ee.internal.common.J2EEDependencyListener.resourceChanged(J2EEDependencyListener.java:72)
	at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:288)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:272)
	at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:148)
	at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:313)
	at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1022)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1809)
	at org.eclipse.core.internal.events.NotificationManager$NotifyJob.run(NotificationManager.java:39)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Jason Sholl CLA 2010-05-17 14:26:12 EDT
Created attachment 168786 [details]
patch
Comment 2 Carl Anderson CLA 2010-05-17 14:42:21 EDT
I approve of this fix.
Comment 3 Rob Stryker CLA 2010-05-18 04:17:23 EDT
should probably be put up for PMC ;)
Comment 4 David Williams CLA 2010-05-18 06:35:02 EDT
Am I reading the patch correctly, that the null structureEdit is ignored? Should it be logged? Since it is an error?
Comment 5 Jason Sholl CLA 2010-05-18 09:59:34 EDT
Yes, the null StructureEdit should be ignored, and no it should not be logged.

While it is rare that such a condition should exist, if it does it implies that the project is no longer a valid VirtualComponent project at all, e.g. the user deleted it or is in the process of deleting it.  Because of the multithreaded nature of WTP and adopter products built on top of it, this sort of scenario can occur.  By simply returning null, the code behaves as if the resource does not exist.  Code further up the chain is then expected to null check the returned resource, because null is an expected return value documented in the API.
Comment 6 David Williams CLA 2010-05-18 11:22:37 EDT
ok, sounds good. Thanks for the extra explanation.
Comment 7 Jason Sholl CLA 2010-05-19 10:30:53 EDT
code checked into head for wtp 3.2 rc2