Buggy code:
public class NameLookup { public static final int ACCEPT_CLASSES = 2 ; public static final int ACCEPT_INTERFACES = 4 ; protected IPackageFragmentRoot [ ] fPackageFragmentRoots = null ; protected Map fPackageFragments ; protected IWorkspace workspace ; protected PerThreadObject unitsToLookInside = new PerThreadObject ( ) ; public NameLookup ( IJavaProject project ) throws JavaModelException { } protected boolean acceptType ( IType type , int acceptFlags ) { } private void configureFromProject ( IJavaProject project ) throws JavaModelException { } private void findAllTypes ( String prefix , boolean partialMatch , int acceptFlags , IJavaElementRequestor requestor ) { } public ICompilationUnit findCompilationUnit ( String qualifiedTypeName ) { } public IPackageFragment findPackageFragment ( IPath path ) { if ( ! ( path . isAbsolute ( ) ) ) { throw new IllegalArgumentException ( Util . bind ( "path.mustBeAbsolute" ) ) ; } IResource possibleFragment = workspace . getRoot ( ) . findMember ( path ) ; if ( possibleFragment == null ) { for ( int i = 0 ; i < ( fPackageFragmentRoots . length ) ; i ++ ) { IPackageFragmentRoot root = fPackageFragmentRoots [ i ] ; if ( ! ( root . isExternal ( ) ) ) { continue ; } IPath rootPath = root . getPath ( ) ; int matchingCount = rootPath . matchingFirstSegments ( path ) ; if ( matchingCount != 0 ) { String name = path . toOSString ( ) ; name = name . substring ( ( ( rootPath . toOSString ( ) . length ( ) ) + 1 ) , name . length ( ) ) ; name = name . replace ( File . separatorChar , '.' ) ; IJavaElement [ ] list = null ; try { list = root . getChildren ( ) ; } catch ( JavaModelException npe ) { continue ; } int elementCount = list . length ; for ( int j = 0 ; j < elementCount ; j ++ ) { IPackageFragment packageFragment = ( ( IPackageFragment ) ( list [ j ] ) ) ; if ( nameMatches ( name , packageFragment , false ) ) { return packageFragment ; } } } } } else { IJavaElement fromFactory = JavaCore . create ( possibleFragment ) ; if ( fromFactory == null ) { return null ; } if ( fromFactory instanceof IPackageFragment ) { return ( ( IPackageFragment ) ( fromFactory ) ) ; } else if ( fromFactory instanceof IJavaProject ) { JavaProject project = ( ( JavaProject ) ( fromFactory ) ) ; try { IClasspathEntry entry = project . getClasspathEntryFor ( path ) ; if ( entry != null ) { <START_BUG> IPackageFragmentRoot root = project . getPackageFragmentRoot ( project . getUnderlyingResource ( ) ) ; <END_BUG> IPackageFragment [ ] pkgs = ( ( IPackageFragment [ ] ) ( fPackageFragments . get ( IPackageFragment . DEFAULT_PACKAGE_NAME ) ) ) ; if ( pkgs == null ) { return null ; } for ( int i = 0 ; i < ( pkgs . length ) ; i ++ ) { if ( pkgs [ i ] . getParent ( ) . equals ( root ) ) { return pkgs [ i ] ; } } } } catch ( JavaModelException e ) { return null ; } } } return null ; } public IPackageFragment [ ] findPackageFragments ( String name , boolean partialMatch ) { } public IType findType ( String typeName , String packageName , boolean partialMatch , int acceptFlags ) { } private IPackageFragment [ ] getPackageFragmentsInRoots ( IPackageFragmentRoot [ ] roots , IJavaProject project ) { } public IType findType ( String name , IPackageFragment pkg , boolean partialMatch , int acceptFlags ) { } public IType findType ( String name , boolean partialMatch , int acceptFlags ) { } protected boolean nameMatches ( String searchName , IJavaElement element , boolean partialMatch ) { } public void seekPackageFragments ( String name , boolean partialMatch , IJavaElementRequestor requestor ) { } public void seekTypes ( String name , IPackageFragment pkg , boolean partialMatch , int acceptFlags , IJavaElementRequestor requestor ) { } protected void seekTypesInBinaryPackage ( String name , IPackageFragment pkg , boolean partialMatch , int acceptFlags , IJavaElementRequestor requestor ) { } protected void seekTypesInSourcePackage ( String name , IPackageFragment pkg , boolean partialMatch , int acceptFlags , IJavaElementRequestor requestor ) { } public void setUnitsToLookInside ( IWorkingCopy [ ] unitsToLookInside ) { } protected void seekQualifiedMemberTypes ( String qualifiedName , IType type , boolean partialMatch , IJavaElementRequestor requestor , int acceptFlags ) { } }

Fix:
IPackageFragmentRoot root = project . getPackageFragmentRoot ( project . getResource ( ) ) ;