Bug 166093 - [search] NPE searching for references to private static method in class file
Summary: [search] NPE searching for references to private static method in class file
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 196923 196974 201109 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-11-28 13:43 EST by John Arthorne CLA
Modified: 2007-09-03 09:04 EDT (History)
6 users (show)

See Also:


Attachments
Proposed patch (25.09 KB, patch)
2006-11-30 04:56 EST, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (1.12 KB, patch)
2007-07-18 12:21 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2006-11-28 13:43:43 EST
Build: I20061121-1845
VM: IBM 1.5 SR3

1) Opened a class file editor in java.util.Arrays
2) Selected a private static method in the outline view:

  private static <T> T[] cloneSubarray(T[] a, int from, int to)

3) Hit Ctrl+Shift+G to start global search for references.

An internal error dialog opens (NPE shown below). This is consistently reproducible for me.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.search.matching.MethodLocator.matchReportReference(MethodLocator.java:339)
	at org.eclipse.jdt.internal.core.search.matching.PatternLocator.matchReportReference(PatternLocator.java:407)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2058)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2464)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2211)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1558)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1042)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1083)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1204)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:219)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:504)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:549)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:143)
	at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:94)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 1 Frederic Fusier CLA 2006-11-30 04:56:35 EST
Created attachment 54766 [details]
Proposed patch

This patch fixes the NPE which happen when method binding is not valid, but also test case where JRE 1.5.0 is attached to a project with 1.4 compliance (I guess this is your test case John, isn't it?).

It passes all JDT tests (CORE+UI) and also does not impact search performance tests on method references (resolved). It was necessary to verify this performance result as the fix is to look at class file version on each document where potential matches are found and use the compliance corresponding the highest version number found there to compile attached source...
Comment 2 Frederic Fusier CLA 2006-11-30 04:57:47 EST
Philippe, do you think it would be an acceptable behavior?
Comment 3 Philipe Mulet CLA 2006-11-30 06:21:07 EST
The project sources should still be compiled at the explicit project compliance level. If not, you would surface erasure matches which are going to be very misleading.

Also, semantics are changing across compliance levels, and could mean headaches in search results.
Comment 4 Frederic Fusier CLA 2006-11-30 06:38:14 EST
Comment on attachment 54766 [details]
Proposed patch

Other options to solve this is either to split documents bundle in several ones (one per source level), or, a better solution, directly extract method references from the class file itself instead of parsing the source again (bug 127442 is already opened for this second option).
Comment 5 John Arthorne CLA 2006-11-30 10:07:09 EST
Yes, my case is projects targetting 1.4 runtime, but compiling against a 1.5 JRE.
Comment 6 Frederic Fusier CLA 2007-07-18 08:28:18 EDT
*** Bug 196923 has been marked as a duplicate of this bug. ***
Comment 7 Art CLA 2007-07-18 08:45:02 EDT
(In reply to comment #6)
> *** Bug 196923 has been marked as a duplicate of this bug. ***
> 
------- Comment #3 from frederic_fusier@fr.ibm.com  2007-07-18 08:29 -------
Can you confirm that you're in the same context than bug 166093 (ie. targetting
1.4 runtime but compiling against JRE 1.5 or 1.6)?

No, it is not the case: I am compiling agains 1.6, and targetting 1.6
Comment 8 Frederic Fusier CLA 2007-07-18 09:29:08 EDT
(In reply to comment #7)
> No, it is not the case: I am compiling agains 1.6, and targetting 1.6
> 
Reopen bug 196923 as it sounds not to be a duplicate...
Comment 9 Frederic Fusier CLA 2007-07-18 12:14:27 EDT
*** Bug 196974 has been marked as a duplicate of this bug. ***
Comment 10 Frederic Fusier CLA 2007-07-18 12:15:55 EDT
*** Bug 196923 has been marked as a duplicate of this bug. ***
Comment 11 Frederic Fusier CLA 2007-07-18 12:21:42 EDT
Created attachment 74074 [details]
New proposed patch

As the number of duplicate increase a lot, I think I will apply a minimal patch to avoid this NPE to occur.

The behavior is not really perfect as the found matches are potential but corresponds to the reality of the user context: 1.5 code is not valid with 1.4 compliance...

Unfortunately, I wasn't able to find a test case with our Java Search tests context to reproduce this problem, so verifier will need to follow steps in comment 0 to verify that this bug is well fixed...
Comment 12 Frederic Fusier CLA 2007-07-19 11:10:39 EDT
Last patch released for 3.4M1 in HEAD stream.
Comment 13 Frederic Fusier CLA 2007-08-03 09:43:50 EDT
Verified for 3.4M1 using build I20070802-0800.
Comment 14 Jerome Lanneluc CLA 2007-08-09 11:19:51 EDT
Frederic, please backport to 3.3.1
Comment 15 Frederic Fusier CLA 2007-08-09 12:46:23 EDT
Patch released for 3.3.1 in R3_3_maintenance stream.
Comment 16 Frederic Fusier CLA 2007-08-09 12:46:55 EDT
.
Comment 17 Frederic Fusier CLA 2007-08-25 04:34:25 EDT
*** Bug 201109 has been marked as a duplicate of this bug. ***
Comment 18 David Audel CLA 2007-09-03 09:04:11 EDT
Verified for 3.3.1 using build M20070831-2000.