Bug 205917 - JavaCore#create(String, WorkingCopyOwner) should deal with null owner
Summary: JavaCore#create(String, WorkingCopyOwner) should deal with null owner
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.5 M1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-10 09:51 EDT by Markus Keller CLA
Modified: 2008-08-06 13:51 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix and regression test (3.36 KB, patch)
2008-05-15 09:18 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 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