Bug 205917

Summary: JavaCore#create(String, WorkingCopyOwner) should deal with null owner
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann
Version: 3.4   
Target Milestone: 3.5 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix and regression test none

Description Markus Keller CLA 2007-10-10 09:51:36 EDT
I20071009-2225

In my code, I accidentally used JavaCore.create(handleIdentifier, null), although JavaCore#create(String, WorkingCopyOwner) does not allow the second parameter to be null.

An ICompilationUnit was created with owner == null, which later lead to NPEs when it was used, e.g. here:
Exception in thread "Info view input computer" java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.CompilationUnit.equals(CompilationUnit.java:453)
	at org.eclipse.jdt.internal.core.JavaElement.equals(JavaElement.java:121)
	at org.eclipse.jdt.internal.core.SourceRefElement.equals(SourceRefElement.java:83)
	at org.eclipse.jdt.internal.core.SourceType.equals(SourceType.java:158)
	at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.isIgnoringNewInput(AbstractInfoView.java:376)
	at org.eclipse.jdt.internal.ui.infoviews.JavadocView.isIgnoringNewInput(JavadocView.java:633)
	at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView$2.run(AbstractInfoView.java:537)

The create(..,..) method should either allow null as owner (and replace it with DefaultWorkingCopyOwner.PRIMARY), or it should throw an NPE or an IllegalArgumentException in this case).

Furthermore, the Javadoc is not fully correct:

 * @param owner the owner of the returned compilation unit, ignored if the
 *   returned element is not a compilation unit

=> owner is only ignored if the element is not a CU *or an element inside a CU* (my call actually created an IType).
Comment 1 Jerome Lanneluc CLA 2008-05-15 09:18:31 EDT
Created attachment 100433 [details]
Proposed fix and regression test
Comment 2 Jerome Lanneluc CLA 2008-06-23 06:27:23 EDT
Fix and test released for 3.5M1
Comment 3 Olivier Thomann CLA 2008-08-06 13:51:12 EDT
Verified for 3.5M1 using I20080805-1307