Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311620 - VirtualReference for the "Pull in classpath elements..." derived reference will NPE if equals() method is called
Summary: VirtualReference for the "Pull in classpath elements..." derived reference wi...
Status: CLOSED DUPLICATE of bug 311598
Alias: None
Product: WTP Common Tools
Classification: WebTools
Component: wst.common (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: wst.common CLA
QA Contact: Carl Anderson CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-04 16:10 EDT by Larry Isaacs CLA
Modified: 2010-05-05 09:47 EDT (History)
0 users

See Also:


Attachments
Patch to avoid NPE in equals() for VirtualReference with null archiveName (1.33 KB, patch)
2010-05-04 16:10 EDT, Larry Isaacs CLA
no flags Details | Diff
Updated patch that avoids NPE plus, for convenience, updates the copyright year (1.75 KB, patch)
2010-05-04 17:38 EDT, Larry Isaacs CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Larry Isaacs CLA 2010-05-04 16:10:51 EDT
Created attachment 167034 [details]
Patch to avoid NPE in equals() for VirtualReference with null archiveName

There are different ways for VirtualReference.equals() to get called, so it's hard to be specific about when the NPE can occur.  Here is one scenario that is reliable for me:

1. In a new workspace, create a Dynamic Web Project and a Utility Project.
2. In the Utility Project, go to the Libraries tab of Java Build Path page and
use the "Add Variable..." button to add JUNIT_HOME/junit.jar to the build path.
3. In the Dynamic Web Project, go to the Deployment Assembly page and click
Add.
3. Select "Referenced Projects Classpath Entries" and click Next.
4. Check the child jar of the Utility Project and click Finish. Note: Bug 311607 addresses why the jar name might not display properly.
5. In the Deployment Assembly page click Add again.
6. Select "Variable" and click Next, then select JUNIT_HOME/junit.jar and click Finish.  Note: For demonstrating the NPE, this second "inclusion" of junit.jar is okay.
7. In the Deployment Assembly page select the newly added JUNIT_HOME/junit.jar and click Remove.

For me, this results in:

java.lang.NullPointerException
at org.eclipse.wst.common.componentcore.internal.resources.VirtualReference.equals(VirtualReference.java:165)
at org.eclipse.jface.viewers.StructuredViewer.equals(StructuredViewer.java:706)
...

The problem is that the VirtualReference for the "Pull in classpath elements from referenced projects" entry returns null for getArchiveName().  The attached patch protects against the NPE.  It does not bother to include the new "isDerived" property in the comparison.  I don't know if it would make sense for all the other properties to be equal and only "isDerived" be different.  If this is possible, then it should be included in the equals() comparison.
Comment 1 Larry Isaacs CLA 2010-05-04 17:38:35 EDT
Created attachment 167052 [details]
Updated patch that avoids NPE plus, for convenience, updates the copyright year
Comment 2 Larry Isaacs CLA 2010-05-05 09:47:27 EDT
Marking as a duplicate of Bug 311598 since the patch it contains includes addressing this NPE and is up for PMC review for WTP 3.2 RC1.

*** This bug has been marked as a duplicate of bug 311598 ***