Buggy code:
char [ ] selector = method . getElementName ( ) . toCharArray ( ) ; char [ ] returnSimpleName ; char [ ] returnQualification ; try { String returnType = Signature . toString ( method . getReturnType ( ) ) . replace ( '$' , '.' ) ; lastDot = returnType . lastIndexOf ( '.' ) ; returnSimpleName = ( lastDot != ( - 1 ) ? returnType . substring ( ( lastDot + 1 ) ) : returnType ) . toCharArray ( ) ; returnQualification = ( lastDot != ( - 1 ) ) ? CharOperation . concat ( IIndexConstants . ONE_STAR , returnType . substring ( 0 , lastDot ) . toCharArray ( ) ) : null ; } catch ( JavaModelException e ) { return null ; } String [ ] parameterTypes = method . getParameterTypes ( ) ; int paramCount = parameterTypes . length ; char [ ] [ ] parameterSimpleNames = new char [ paramCount ] [ ] ; char [ ] [ ] parameterQualifications = new char [ paramCount ] [ ] ; for ( int i = 0 ; i < paramCount ; i ++ ) { String signature = Signature . toString ( parameterTypes [ i ] ) . replace ( '$' , '.' ) ; lastDot = signature . lastIndexOf ( '.' ) ; parameterSimpleNames [ i ] = ( lastDot != ( - 1 ) ? signature . substring ( ( lastDot + 1 ) ) : signature ) . toCharArray ( ) ; parameterQualifications [ i ] = ( lastDot != ( - 1 ) ) ? CharOperation . concat ( IIndexConstants . ONE_STAR , signature . substring ( 0 , lastDot ) . toCharArray ( ) ) : null ; } switch ( limitTo ) { case IJavaSearchConstants . DECLARATIONS : if ( isConstructor ) { searchPattern = new ConstructorDeclarationPattern ( declaringSimpleName , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , parameterQualifications , parameterSimpleNames ) ; } else { searchPattern = new MethodDeclarationPattern ( selector , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , declaringSimpleName , returnQualification , returnSimpleName , parameterQualifications , parameterSimpleNames ) ; } break ; case IJavaSearchConstants . REFERENCES : if ( isConstructor ) { searchPattern = new ConstructorReferencePattern ( declaringSimpleName , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , parameterQualifications , parameterSimpleNames , method . getDeclaringType ( ) ) ; } else { searchPattern = new MethodReferencePattern ( selector , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , declaringSimpleName , returnQualification , returnSimpleName , parameterQualifications , parameterSimpleNames , method . getDeclaringType ( ) ) ; } break ; case IJavaSearchConstants . ALL_OCCURRENCES : if ( isConstructor ) { searchPattern = new OrPattern ( new ConstructorDeclarationPattern ( declaringSimpleName , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , parameterQualifications , parameterSimpleNames ) , new ConstructorReferencePattern ( declaringSimpleName , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , parameterQualifications , parameterSimpleNames , method . getDeclaringType ( ) ) ) ; } else { searchPattern = new OrPattern ( new MethodDeclarationPattern ( selector , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , declaringSimpleName , returnQualification , returnSimpleName , parameterQualifications , parameterSimpleNames ) , new MethodReferencePattern ( selector , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE , declaringQualification , declaringSimpleName , returnQualification , returnSimpleName , parameterQualifications , parameterSimpleNames , method . getDeclaringType ( ) ) ) ; } break ; } break ; case IJavaElement . TYPE : IType type = ( ( IType ) ( element ) ) ; searchPattern = SearchPattern . createTypePattern ( type . getElementName ( ) . toCharArray ( ) , type . getPackageFragment ( ) . getElementName ( ) . toCharArray ( ) , SearchPattern . enclosingTypeNames ( type ) , limitTo ) ; break ; case IJavaElement . PACKAGE_DECLARATION : case IJavaElement . PACKAGE_FRAGMENT : searchPattern = SearchPattern . createPackagePattern ( element . getElementName ( ) , limitTo , IJavaSearchConstants . EXACT_MATCH , IJavaSearchConstants . CASE_SENSITIVE ) ; break ; } <START_BUG> if ( ( searchPattern != null ) && ( limitTo == ( IJavaSearchConstants . REFERENCES ) ) ) { <END_BUG> searchPattern . focus = element ; } return searchPattern ; } private static SearchPattern createTypePattern ( char [ ] simpleName , char [ ] packageName , char [ ] [ ] enclosingTypeNames , int limitTo ) { } private static SearchPattern createTypePattern ( String patternString , int limitTo , int matchMode , boolean isCaseSensitive ) { } protected abstract void decodeIndexEntry ( IEntryResult entryResult ) { } private static char [ ] [ ] enclosingTypeNames ( IType type ) { } public abstract void feedIndexRequestor ( IIndexSearchRequestor requestor , int detailLevel , int [ ] references , IndexInput input , IJavaSearchScope scope ) throws IOException { } public void findIndexMatches ( IIndex index , IIndexSearchRequestor requestor , int detailLevel , IProgressMonitor progressMonitor , IJavaSearchScope scope ) throws IOException { } public void findIndexMatches ( IndexInput input , IIndexSearchRequestor requestor , int detailLevel , IProgressMonitor progressMonitor , IJavaSearchScope scope ) throws IOException { } public abstract char [ ] indexEntryPrefix ( ) { } protected void matchCheck ( AstNode node , MatchSet set ) { } protected abstract int matchContainer ( ) { } public boolean matchesBinary ( Object binaryInfo , Object enclosingBinaryInfo ) { } protected boolean matchesName ( char [ ] pattern , char [ ] name ) { } protected boolean matchesType ( char [ ] simpleNamePattern , char [ ] qualificationPattern , char [ ] fullyQualifiedTypeName ) { } protected abstract boolean matchIndexEntry ( ) { } protected void matchReportImportRef ( ImportReference importRef , Binding binding , IJavaElement element , int accuracy , MatchLocator locator ) throws CoreException { } protected void matchReportReference ( AstNode reference , IJavaElement element , int accuracy , MatchLocator locator ) throws CoreException { } protected char [ ] toArrayName ( char [ ] simpleName , int dimensions ) { } public String toString ( ) { }

Fix:
if ( searchPattern != null ) {