Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355605

Summary: NPE in HierarchyResolver
Product: [Eclipse Project] JDT Reporter: Dani Megert <daniel_megert>
Component: CoreAssignee: Jay Arthanareeswaran <jarthana>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jarthana, Olivier_Thomann, pbenedict, satyam.kandula
Version: 3.8Flags: satyam.kandula: review+
Target Milestone: 3.8 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Patch with test none

Description Dani Megert CLA 2011-08-24 03:12:27 EDT
I20110823-0925.

1. check out 'org.eclipse.jface.text' from CVS
2. copy "AdditionalInfoController:114" into clipboard
3. Navigate > Copy from Clipboard
4. Ctrl+click on getInfo and select 'Open Implementation'

==>

!ENTRY org.eclipse.jdt.ui 4 0 2011-08-24 09:00:03.360
!MESSAGE An error occurred while searching for implementations of method 'setInfo'. See error log for details.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.setFocusType(HierarchyResolver.java:848)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.createHierarchyResolver(MatchLocator.java:680)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1064)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1124)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1256)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:231)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:584)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink$1.run(JavaElementImplementationHyperlink.java:251)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 1 Olivier Thomann CLA 2011-08-24 10:01:18 EDT
Satyam, please take a look. If this is a regression over 3.6.x, we might fix it for 3.7.2.
Comment 2 Jay Arthanareeswaran CLA 2011-08-24 10:07:31 EDT
Here is a simplified test case

-------
public class Q {
	class R{
		void setInfo(String abc) {
		}
		class S {
		}
		class T {
		}
		
		S s = new S() {
			T t = new T()  {
				void myMethod() {
					setInfo("a");
				}
			};
		};
	}
}
--------
When you try to find the implementation for setInfo, the NPE is thrown. Note that this doesn't seem to affect the functionality as such. The cursor is taken to the appropriate position.

And looking at the code, this must have been introduced by the fix for bug 169678 and I think this might have always been around. On investigation I found that we try to look for member types even though what we have at hand is an anonymous and in the process a null focusType is being set at HierarchyResolver:848. We probably don't need that code to be executed in this case as the original fix (for bug 169678) seemed to target static member types.
Comment 3 Olivier Thomann CLA 2011-08-24 10:12:51 EDT
Reassigning to Jay since he is already looking at it.
Comment 4 Jay Arthanareeswaran CLA 2011-08-30 06:35:21 EDT
Created attachment 202401 [details]
Proposed fix

Looks like all we have to do is just to avoid the NPE. And since the null scenario has already been taken care of in MatchLocator#createHierarchyResolver(), returning at the first occurrence of null would do. The patch also keeps the null value assigned to MatchLocator#focusType.
Comment 5 Jay Arthanareeswaran CLA 2011-09-05 00:42:21 EDT
Satyam, can you please review the patch. Should be a simple one.
Comment 6 Satyam Kandula CLA 2011-09-05 01:46:52 EDT
Patch looks good. Do you plan to have a testcase?
Comment 7 Jay Arthanareeswaran CLA 2011-09-05 10:26:15 EDT
(In reply to comment #6)
> Patch looks good. Do you plan to have a testcase?

Okay, I will update with a test in a bit.
Comment 8 Jay Arthanareeswaran CLA 2011-09-07 08:08:32 EDT
Created attachment 202886 [details]
Patch with test

This patch includes a new test.

Satyam, can you please look at the test and tell me how I can avoid the multiple searches to reach the method invocation inside the nested anonymous? Thanks.
Comment 9 Jay Arthanareeswaran CLA 2011-09-08 22:42:15 EDT
Released in HEAD 3.8M2.
Comment 10 Jay Arthanareeswaran CLA 2011-09-08 22:43:47 EDT
.
Comment 11 Paul Benedict CLA 2011-09-09 00:25:02 EDT
I found lines 849-850 to be odd:
>> if (this.focusType == null)
>>     return this.focusType;

Wouldn't it be more straightforward to return null?
Comment 12 Jay Arthanareeswaran CLA 2011-09-09 01:23:52 EDT
(In reply to comment #11)
> Wouldn't it be more straightforward to return null?

Yes, indeed. I have corrected that in the HEAD also shortened the testcase a bit.
Comment 13 Satyam Kandula CLA 2011-09-13 07:03:19 EDT
Verified for 3.8M2 using build I20110912-0800