Bug 215684 - [search] NPE from Java search
Summary: [search] NPE from Java search
Status: CLOSED WONTFIX
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: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2008-01-17 12:44 EST by Leho Nigul CLA
Modified: 2020-05-20 11:24 EDT (History)
0 users

See Also:


Attachments
Sample project on which I see this exception happen (3.81 KB, application/x-zip-compressed)
2008-01-17 12:44 EST, Leho Nigul CLA
no flags Details
Class where I invoke search API (2.18 KB, application/octet-stream)
2008-01-25 13:38 EST, Leho Nigul CLA
no flags Details
Requestor1 (1.55 KB, application/octet-stream)
2008-01-25 13:39 EST, Leho Nigul CLA
no flags Details
Requestor2 (745 bytes, application/octet-stream)
2008-01-25 13:40 EST, Leho Nigul CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leho Nigul CLA 2008-01-17 12:44:51 EST
Created attachment 87182 [details]
Sample project on which I see this exception happen

Build ID: I20071213-1700

Steps To Reproduce:

I have the following code that uses JDT search APIs:

			SearchPattern pattern = null;
			for (int v=0;v<types.size();v++)
			{
				IType typ = types.get(v);
				SearchPattern pattern1 = SearchPattern.createPattern(typ, IJavaSearchConstants.REFERENCES);
				if(pattern!=null)
				{
					pattern = SearchPattern.createOrPattern(pattern, pattern1);
				}
				else
				{
					pattern = pattern1;
				}
				
			}

			if(pattern!=null)
			{
				
				try
				{
					searchEngine.search(pattern, participats, scope, requestor, null);
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
				return requestor.getResults();
			}

The basic idea behind my code, is that I have a number of IType objects (which represent Annotation types) and I want find references to these objects. Participats and requestor are very simple.

When this code is ran I get the following exception:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:235)
	at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:185)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1516)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1027)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1068)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1190)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:217)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:500)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:550)


More information:
Comment 1 Frederic Fusier CLA 2008-01-17 13:46:27 EST
Please provide the entire code to make it easier to reproduce, thanks
Comment 2 Leho Nigul CLA 2008-01-25 13:38:51 EST
Created attachment 87893 [details]
Class where I invoke search API
Comment 3 Leho Nigul CLA 2008-01-25 13:39:58 EST
Created attachment 87894 [details]
Requestor1
Comment 4 Leho Nigul CLA 2008-01-25 13:40:27 EST
Created attachment 87895 [details]
Requestor2
Comment 5 Leho Nigul CLA 2008-01-25 13:41:30 EST
Please see provided attachements to see my code. Please let me know if you any additional info.
Comment 6 Frederic Fusier CLA 2008-02-29 09:41:14 EST
I cannot reproduce the NPE using the given sample project + search and requestors snippets...

Note that using Search fine grain will solve the problem in a faster way (around 3 times faster):

private Set findAnnotationReferences(IJavaElement javaElement) {
    IJavaSearchScope scope = 
        SearchEngine.createJavaSearchScope(new IJavaElement[] { javaElement });
    SearchAllAnnotationsReferencesRequestor requestor = 
        new SearchAllAnnotationsReferencesRequestor();
    SearchPattern pattern = SearchPattern.createPattern("*", 
        IJavaSearchConstants.ANNOTATION_TYPE, 
        IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, 
        SearchPattern.R_PATTERN_MATCH); //$NON-NLS-1$
    try {
        new SearchEngine().search(pattern, 
            new SearchParticipant[] { 
                SearchEngine.getDefaultSearchParticipant()
            }, 
            scope,
            requestor,
            null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return requestor.results;
}

class SearchAllAnnotationsReferencesRequestor extends SearchRequestor {
    Set results = new HashSet();
    public void acceptSearchMatch(SearchMatch match) throws CoreException {
        this.results.add(match.getElement());
    }
}
Comment 7 Eclipse Genie CLA 2020-05-20 11:24:11 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.