Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 268678 - [navigation] NPE in JavaElementImplementationHyperlink
Summary: [navigation] NPE in JavaElementImplementationHyperlink
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M7   Edit
Assignee: Raksha Vasisht CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-15 13:51 EDT by Andrey Loskutov CLA
Modified: 2009-03-16 15:01 EDT (History)
2 users (show)

See Also:


Attachments
Patch with added null checks. (3.56 KB, patch)
2009-03-16 08:46 EDT, Raksha Vasisht CLA
daniel_megert: iplog+
daniel_megert: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2009-03-15 13:51:43 EDT
Build ID: 3.5M6

Steps To Reproduce:

1. Open org.eclipse.core.internal.resources.Resource.class (resources plugin should NOT be imported as *source* project in the workspace)
2. Ctrl+Mouse click on any method declaration
3. NPE:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink.open(JavaElementImplementationHyperlink.java:164)
	at org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter$LinkListInformationControl.openSelectedLink(MultipleHyperlinkPresenter.java:319)
	at org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter$LinkListInformationControl.access$1(MultipleHyperlinkPresenter.java:314)
	at org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter$3.widgetSelected(MultipleHyperlinkPresenter.java:275)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)

Related source code expects to see resolved type binding, which is null:

ITypeBinding binding= expression.resolveTypeBinding();
elem= binding.getJavaElement();
Comment 1 Dani Megert CLA 2009-03-16 04:42:04 EDT
Andrei, I can see that a NPE is possible from the code but I cannot reproduce using your steps as I understood them:

1. start fresh workspace
2. import org.eclipse.core.resources as binary (not as source)
3. open type 'Resource'
4. click on a method declaration

OR:

1. start fresh workspace
2. import a project that require org.eclipse.core.resources
   (org.eclipse.core.resources not explicitly imported)
3. open type 'Resource'
4. click on a method declaration

Can you provide more detailed steps?
Comment 2 Dani Megert CLA 2009-03-16 05:56:38 EDT
Raksha, please protect all calls in the open method that can return against NPE.
Comment 3 Raksha Vasisht CLA 2009-03-16 08:46:51 EDT
Created attachment 128909 [details]
Patch with added null checks.
Comment 4 Dani Megert CLA 2009-03-16 08:58:34 EDT
Thanks for the patch Raksha.

Committed to HEAD
Available in builds > N20090315-2000.

Andrei, it would still be good to get a test case.
Comment 5 Markus Keller CLA 2009-03-16 15:01:00 EDT
> Created an attachment (id=128909) [details]
> Patch with added null checks.

I removed the "if (parent != null)" check in HEAD, since it's redundant (all branches of the nested if-else statement do an instanceof check first).

Also refactored the null check for parentTypeBinding a bit (do it only once) and used JdtFlags.isAbstract(..) to simplify the test in the search requestor.


I could reproduce with these steps:
1. start fresh workspace
2. org.eclipse.core.resources as binary
3. remove target platform
4. open type 'Resource'
5. press Ctrl and click Open Implementation on the declaration of the accept(..) method

Verified that the problem is gone in HEAD. We open the quick type hierarchy now, because the type is full of (invisible) compile errors due to the missing dependencies.