Buggy code:
public class PackageReferenceLocator extends PatternLocator { protected PackageReferencePattern pattern ; public static boolean isDeclaringPackageFragment ( IPackageFragment packageFragment , ReferenceBinding typeBinding ) { } public PackageReferenceLocator ( PackageReferencePattern pattern ) { } public int match ( ASTNode node , MatchingNodeSet nodeSet ) { } public int match ( Reference node , MatchingNodeSet nodeSet ) { } public int match ( TypeReference node , MatchingNodeSet nodeSet ) { } protected int matchLevel ( ImportReference importRef ) { } protected int matchLevelForTokens ( char [ ] [ ] tokens ) { } protected void matchLevelAndReportImportRef ( ImportReference importRef , Binding binding , MatchLocator locator ) throws CoreException { } protected void matchReportImportRef ( ImportReference importRef , Binding binding , IJavaElement element , int accuracy , MatchLocator locator ) throws CoreException { } protected void matchReportReference ( ASTNode reference , IJavaElement element , Binding elementBinding , int accuracy , MatchLocator locator ) throws CoreException { long [ ] positions = null ; int last = - 1 ; if ( reference instanceof ImportReference ) { ImportReference importRef = ( ( ImportReference ) ( reference ) ) ; positions = importRef . sourcePositions ; <START_BUG> last = ( importRef . onDemand ) ? positions . length : ( positions . length ) - 1 ; <END_BUG> } else { TypeBinding typeBinding = null ; if ( reference instanceof QualifiedNameReference ) { QualifiedNameReference qNameRef = ( ( QualifiedNameReference ) ( reference ) ) ; positions = qNameRef . sourcePositions ; switch ( ( qNameRef . bits ) & ( ASTNode . RestrictiveFlagMASK ) ) { case Binding . FIELD : typeBinding = qNameRef . actualReceiverType ; break ; case Binding . TYPE : if ( ( qNameRef . binding ) instanceof TypeBinding ) typeBinding = ( ( TypeBinding ) ( qNameRef . binding ) ) ; break ; case Binding . VARIABLE : case ( Binding . TYPE ) | ( Binding . VARIABLE ) : Binding binding = qNameRef . binding ; if ( binding instanceof TypeBinding ) { typeBinding = ( ( TypeBinding ) ( binding ) ) ; } else if ( binding instanceof ProblemFieldBinding ) { typeBinding = qNameRef . actualReceiverType ; last = ( qNameRef . tokens . length ) - ( ( qNameRef . otherBindings ) == null ? 2 : ( qNameRef . otherBindings . length ) + 2 ) ; } else if ( binding instanceof ProblemBinding ) { ProblemBinding pbBinding = ( ( ProblemBinding ) ( binding ) ) ; typeBinding = pbBinding . searchType ; last = CharOperation . occurencesOf ( '.' , pbBinding . name ) ; } break ; } } else if ( reference instanceof QualifiedTypeReference ) { QualifiedTypeReference qTypeRef = ( ( QualifiedTypeReference ) ( reference ) ) ; positions = qTypeRef . sourcePositions ; typeBinding = qTypeRef . resolvedType ; } else if ( reference instanceof JavadocSingleTypeReference ) { JavadocSingleTypeReference jsTypeRef = ( ( JavadocSingleTypeReference ) ( reference ) ) ; positions = new long [ 1 ] ; positions [ 0 ] = ( ( ( long ) ( jsTypeRef . sourceStart ) ) << 32 ) + ( jsTypeRef . sourceEnd ) ; typeBinding = jsTypeRef . resolvedType ; } if ( positions == null ) return ; if ( typeBinding instanceof ArrayBinding ) typeBinding = ( ( ArrayBinding ) ( typeBinding ) ) . leafComponentType ; if ( typeBinding instanceof ProblemReferenceBinding ) typeBinding = ( ( ProblemReferenceBinding ) ( typeBinding ) ) . closestMatch ( ) ; if ( typeBinding instanceof ReferenceBinding ) { PackageBinding pkgBinding = ( ( ReferenceBinding ) ( typeBinding ) ) . fPackage ; if ( pkgBinding != null ) last = pkgBinding . compoundName . length ; } ReferenceBinding enclosingType = ( typeBinding == null ) ? null : typeBinding . enclosingType ( ) ; if ( enclosingType != null ) { int length = positions . length ; while ( ( enclosingType != null ) && ( length > 0 ) ) { length -- ; enclosingType = enclosingType . enclosingType ( ) ; } if ( length <= 1 ) return ; } } if ( last == ( - 1 ) ) { last = this . pattern . segments . length ; } if ( last == 0 ) return ; if ( last > ( positions . length ) ) last = positions . length ; int sourceStart = ( ( int ) ( ( positions [ 0 ] ) > > > 32 ) ) ; int sourceEnd = ( ( int ) ( positions [ ( last - 1 ) ] ) ) ; match = locator . newPackageReferenceMatch ( element , accuracy , sourceStart , ( ( sourceEnd - sourceStart ) + 1 ) , reference ) ; locator . report ( match ) ; } protected int referenceType ( ) { } public int resolveLevel ( ASTNode node ) { } public int resolveLevel ( Binding binding ) { } protected int resolveLevel ( QualifiedNameReference qNameRef ) { } public String toString ( ) { } }

Fix:
last = ( ( ( importRef . bits ) & ( ASTNode . OnDemand ) ) != 0 ) ? positions . length : ( positions . length ) - 1 ;