Buggy code:
protected BinaryTypeBinding cacheBinaryType ( IType type , IBinaryType binaryType ) throws JavaModelException { } protected char [ ] [ ] [ ] computeSuperTypeNames ( IType focusType ) { } protected IJavaElement createHandle ( AbstractMethodDeclaration method , IJavaElement parent ) { } IMethod createBinaryMethodHandle ( IType type , char [ ] methodSelector , char [ ] [ ] argumentTypeNames ) { } private IJavaElement createMethodHandle ( IType type , String methodName , String [ ] parameterTypeSignatures ) { } protected IJavaElement createHandle ( FieldDeclaration fieldDeclaration , TypeDeclaration typeDeclaration , IJavaElement parent ) { } protected IJavaElement createHandle ( AbstractVariableDeclaration variableDeclaration , IJavaElement parent ) { } protected boolean createHierarchyResolver ( IType focusType , PossibleMatch [ ] possibleMatches ) { } protected IJavaElement createImportHandle ( ImportReference importRef ) { } protected IJavaElement createPackageDeclarationHandle ( CompilationUnitDeclaration unit ) { } protected IType createTypeHandle ( String simpleTypeName ) { } protected boolean encloses ( IJavaElement element ) { } private long findLastTypeArgumentInfo ( TypeReference typeRef ) { } protected IBinaryType getBinaryInfo ( ClassFile classFile , IResource resource ) throws CoreException { } protected IType getFocusType ( ) { } protected void getMethodBodies ( CompilationUnitDeclaration unit , MatchingNodeSet nodeSet ) { } protected TypeBinding getType ( Object typeKey , char [ ] typeName ) { } public MethodBinding getMethodBinding ( MethodPattern methodPattern ) { } protected boolean hasAlreadyDefinedType ( CompilationUnitDeclaration parsedUnit ) { } public void initialize ( JavaProject project , int possibleMatchSize ) throws JavaModelException { } protected void locateMatches ( JavaProject javaProject , PossibleMatch [ ] possibleMatches , int start , int length ) throws CoreException { } protected void locateMatches ( JavaProject javaProject , PossibleMatchSet matchSet , int expected ) throws CoreException { } public void locateMatches ( SearchDocument [ ] searchDocuments ) throws CoreException { } public void locatePackageDeclarations ( SearchParticipant participant ) throws CoreException { } protected void locatePackageDeclarations ( SearchPattern searchPattern , SearchParticipant participant ) throws CoreException { if ( searchPattern instanceof OrPattern ) { SearchPattern [ ] patterns = ( ( OrPattern ) ( searchPattern ) ) . patterns ; for ( int i = 0 , length = patterns . length ; i < length ; i ++ ) locatePackageDeclarations ( patterns [ i ] , participant ) ; } else if ( searchPattern instanceof PackageDeclarationPattern ) { IJavaElement focus = ( ( InternalSearchPattern ) ( searchPattern ) ) . focus ; if ( focus != null ) { if ( encloses ( focus ) ) { SearchMatch match = new PackageDeclarationMatch ( focus . getAncestor ( IJavaElement . PACKAGE_FRAGMENT ) , SearchMatch . A_ACCURATE , ( - 1 ) , ( - 1 ) , participant , focus . getResource ( ) ) ; report ( match ) ; } return ; } PackageDeclarationPattern pkgPattern = ( ( PackageDeclarationPattern ) ( searchPattern ) ) ; boolean isWorkspaceScope = ( this . scope ) == ( JavaModelManager . getJavaModelManager ( ) . getWorkspaceScope ( ) ) ; IPath [ ] scopeProjectsAndJars = ( isWorkspaceScope ) ? null : this . scope . enclosingProjectsAndJars ( ) ; int scopeLength = ( isWorkspaceScope ) ? 0 : scopeProjectsAndJars . length ; IJavaProject [ ] projects = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) . getJavaProjects ( ) ; SimpleSet packages = new SimpleSet ( ) ; for ( int i = 0 , length = projects . length ; i < length ; i ++ ) { IJavaProject javaProject = projects [ i ] ; if ( ! isWorkspaceScope ) { boolean found = false ; for ( int j = 0 ; j < scopeLength ; j ++ ) { if ( javaProject . getPath ( ) . equals ( scopeProjectsAndJars [ j ] ) ) { found = true ; break ; } } if ( ! found ) continue ; } this . nameLookup = ( ( JavaProject ) ( projects [ i ] ) ) . newNameLookup ( this . workingCopies ) ; <START_BUG> IPackageFragment [ ] packageFragments = this . nameLookup . findPackageFragments ( new String ( pkgPattern . pkgName ) , true , true ) ; <END_BUG> int pLength = ( packageFragments == null ) ? 0 : packageFragments . length ; for ( int p = 0 ; p < pLength ; p ++ ) { IPackageFragment fragment = packageFragments [ p ] ; if ( ( packages . addIfNotIncluded ( fragment ) ) == null ) continue ; if ( encloses ( fragment ) ) { IResource resource = fragment . getResource ( ) ; if ( resource == null ) resource = javaProject . getProject ( ) ; try { if ( encloses ( fragment ) ) { SearchMatch match = new PackageDeclarationMatch ( fragment , SearchMatch . A_ACCURATE , ( - 1 ) , ( - 1 ) , participant , resource ) ; report ( match ) ; } } catch ( JavaModelException e ) { throw e ; } catch ( CoreException e ) { throw new JavaModelException ( e ) ; } } } } } } protected IType lookupType ( ReferenceBinding typeBinding ) { } public SearchMatch newDeclarationMatch ( IJavaElement element , Binding binding , int accuracy , int offset , int length ) { } public SearchMatch newDeclarationMatch ( IJavaElement element , Binding binding , int accuracy , int offset , int length , SearchParticipant participant , IResource resource ) { } public SearchMatch newFieldReferenceMatch ( IJavaElement enclosingElement , Binding enclosingBinding , int accuracy , int offset , int length , ASTNode reference ) { } public SearchMatch newLocalVariableReferenceMatch ( IJavaElement enclosingElement , int accuracy , int offset , int length , ASTNode reference ) { } public SearchMatch newMethodReferenceMatch ( IJavaElement enclosingElement , Binding enclosingBinding , int accuracy , int offset , int length , boolean isConstructor , boolean isSynthetic , ASTNode reference ) { } public SearchMatch newPackageReferenceMatch ( IJavaElement enclosingElement , int accuracy , int offset , int length , ASTNode reference ) { }

Fix:
IPackageFragment [ ] packageFragments = this . nameLookup . findPackageFragments ( new String ( pkgPattern . pkgName ) , false , true ) ;