Community
Participate
Working Groups
The code below is failing. The elems list hold valid interface IType objects and the constructed SearchPatterns are not null. JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); IJavaSearchScope scope= factory.createJavaSearchScope(new IJavaElement[]{myJavaProject}, false); SearchPattern patternA = SearchPattern.createPattern((IJavaElement)elems.get(0), IJavaSearchConstants.IMPLEMENTORS, 0); SearchPattern patternB = SearchPattern.createPattern((IJavaElement)elems.get(1), IJavaSearchConstants.IMPLEMENTORS, 0); SearchPattern andedPattern = SearchPattern.createAndPattern(patternA, patternB); SearchRequestor requestor = new Searcher(); SearchEngine engine = new SearchEngine(); try { engine.search(andedPattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, scope, requestor, null); } catch (CoreException e) { ... } ... This results in a NullPointerException in MatchLocator: java.lang.NullPointerException at org.eclipse.jdt.internal.core.search.matching.MatchLocator.<init>(MatchLocator.java:351) at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:85) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:212) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:503) at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:538) ... The problem seems to stem from the static method PatternLocator.patternLocator(SearchPattern pattern) returning null.
Indeed, PatternLocator.patternLocator(SearchPattern) can return null. We should either handle the null case or return a non-null pattern. In the same way, the call to PatternLocator.patternLocator(SearchPattern pattern) in org.eclipse.jdt.internal.core.search.matching.OrLocator can also put null patterns in the patternLocators array. There is no null check when retrieving the pattern locators.
Created attachment 73026 [details] Proposed patch Note that for AND patterns, Search Engine returns matches which will both be returned by each pattern of the AND. Unfortunately that means it does not return any match for the initial bug scenario given in comment 0 as results of requests "Implementors of I1" and "Implementors of I2" have no real common match. The goal of this patch is just to: 1) avoid the NPE 2) implement minimal behavior for the AND pattern allowing deeper implementation in case of a strong need appears in the future...
Released for 3.4M1 in HEAD stream.
Verified (from code of added tests) for 3.4M1 using build I20070802-0800.
closing