Bug 232037 - CompilationUnit#equals(Object) throws NPE if owner is null
Summary: CompilationUnit#equals(Object) throws NPE if owner is null
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 232045 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-05-14 06:08 EDT by Markus Keller CLA
Modified: 2008-05-16 04:05 EDT (History)
1 user (show)

See Also:
frederic_fusier: review+


Attachments
Proposed fix and regression tests (8.42 KB, patch)
2008-05-14 13:08 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-05-14 06:08:20 EDT
I20080513-2000

CompilationUnit#equals(Object) throws NPE if owner is null. Other places in the CU check owner for null.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.CompilationUnit.equals(CompilationUnit.java:488)
	at org.eclipse.jface.viewers.StructuredSelection.equals(StructuredSelection.java:142)
	at org.eclipse.ui.internal.util.Util.equals(Util.java:366)
	at org.eclipse.ui.internal.services.ActivePartSourceProvider.checkActivePart(ActivePartSourceProvider.java:191)
	at org.eclipse.ui.internal.services.ActivePartSourceProvider$2.windowDeactivated(ActivePartSourceProvider.java:125)
	at org.eclipse.ui.internal.Workbench$13.run(Workbench.java:824)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.ui.internal.Workbench.fireWindowDeactivated(Workbench.java:822)
	at org.eclipse.ui.internal.WorkbenchWindow$26.shellDeactivated(WorkbenchWindow.java:3008)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:104)
...
Comment 1 Markus Keller CLA 2008-05-14 06:21:39 EDT
Steps (only do this in a runtime workbench, since it will put you in the vicious circle from bug 232036!):

- paste to Package Explorer:

package p;
public class C {
	void m() {
		new java.util.List<URL>();
	}
}

- open ASTView (with bindings recovery, using ASTParser.createAST)
- select new java.util.List<URL>()
- open type binding for ClassInstanceCreation
- double-click the last element (the red "> CompilationUnit...")
- click OK
=> you're trapped in bug 232036
Comment 2 Markus Keller CLA 2008-05-14 06:23:09 EDT
Replacing
    this.owner.equals(other.owner)
with
    Util.equalOrNull(this.owner, other.owner)
solved the problem for me, but I'm not sure whether the owner should have been null in the first place.
Comment 3 Jerome Lanneluc CLA 2008-05-14 13:08:21 EDT
Created attachment 100237 [details]
Proposed fix and regression tests
Comment 4 Jerome Lanneluc CLA 2008-05-14 13:08:55 EDT
Frederic can you please review?
Comment 5 Frederic Fusier CLA 2008-05-14 13:22:01 EDT
Patch looks good: +1
Comment 6 Jerome Lanneluc CLA 2008-05-14 13:34:30 EDT
*** Bug 232045 has been marked as a duplicate of this bug. ***
Comment 7 Jerome Lanneluc CLA 2008-05-14 16:49:32 EDT
Fix and tests released for 3.4RC1
Comment 8 David Audel CLA 2008-05-16 04:05:38 EDT
Verified for 3.4RC1 using I20080515-2000.