Buggy code:
public final class ImportRewriteAnalyzer { private ICompilationUnit compilationUnit ; private ArrayList packageEntries ; private int importOnDemandThreshold ; private boolean filterImplicitImports ; private boolean findAmbiguousImports ; private List importsCreated ; private List staticImportsCreated ; private IRegion replaceRange ; private int flags = 0 ; private static final int F_NEEDS_LEADING_DELIM = 2 ; private static final int F_NEEDS_TRAILING_DELIM = 4 ; private static final String JAVA_LANG = "java.lang" ; public ImportRewriteAnalyzer ( ICompilationUnit cu , CompilationUnit root , String [ ] preferenceOrder , int importThreshold , boolean restoreExistingImports ) { } private void addPreferenceOrderHolders ( ImportRewriteAnalyzer . PackageEntry [ ] preferenceOrder ) { } private static String getQualifier ( ImportDeclaration decl ) { } private static String getFullName ( ImportDeclaration decl ) { } private void addExistingImports ( CompilationUnit root ) { } public void setFilterImplicitImports ( boolean filterImplicitImports ) { } public void setFindAmbiguousImports ( boolean findAmbiguousImports ) { } private static class PackageMatcher { private String newName ; private String bestName ; private int bestMatchLen ; public PackageMatcher ( ) { } public void initialize ( String newImportName , String bestImportName ) { } public boolean isBetterMatch ( String currName , boolean preferCurr ) { } private boolean sameMatchLenTest ( String currName ) { } } static int getCommonPrefixLength ( String s , String t ) { } static char getCharAt ( String str , int index ) { } private ImportRewriteAnalyzer . PackageEntry findBestMatch ( String newName , boolean isStatic ) { } private static boolean isImplicitImport ( String qualifier , ICompilationUnit cu ) { } public void addImport ( String fullTypeName , boolean isStatic ) { } public boolean removeImport ( String qualifiedName , boolean isStatic ) { } private int getIndexAfterStatics ( ) { } private void sortIn ( String typeContainerName , ImportRewriteAnalyzer . ImportDeclEntry decl , boolean isStatic ) { } private IRegion evaluateReplaceRange ( CompilationUnit root ) { List imports = root . imports ( ) ; if ( ! ( imports . isEmpty ( ) ) ) { ImportDeclaration first = ( ( ImportDeclaration ) ( imports . get ( 0 ) ) ) ; ImportDeclaration last = ( ( ImportDeclaration ) ( imports . get ( ( ( imports . size ( ) ) - 1 ) ) ) ) ; <START_BUG> int startPos = root . getExtendedStartPosition ( first ) ; <END_BUG> int endPos = ( root . getExtendedStartPosition ( last ) ) + ( root . getExtendedLength ( last ) ) ; int endLine = root . getLineNumber ( endPos ) ; if ( endLine > 0 ) { int nextLinePos = root . getPosition ( ( endLine + 1 ) , 0 ) ; if ( nextLinePos >= 0 ) { int firstTypePos = ImportRewriteAnalyzer . getFirstTypeBeginPos ( root ) ; if ( ( firstTypePos != ( - 1 ) ) && ( firstTypePos < nextLinePos ) ) { endPos = firstTypePos ; } else { endPos = nextLinePos ; } } } return new Region ( startPos , ( endPos - startPos ) ) ; } else { int start = getPackageStatementEndPos ( root ) ; return new Region ( start , 0 ) ; } } public MultiTextEdit getResultingEdits ( IProgressMonitor monitor ) throws JavaModelException { } private void removeAndInsertNew ( IBuffer buffer , int contentOffset , int contentEnd , ArrayList stringsToInsert , MultiTextEdit resEdit ) { } private int findInBuffer ( IBuffer buffer , String str , int start , int end ) { } private boolean useSpaceBetweenGroups ( ) { } private Set evaluateStarImportConflicts ( IProgressMonitor monitor ) throws JavaModelException { } private String getNewImportString ( String importName , boolean isStatic , String lineDelim ) { } private static int getFirstTypeBeginPos ( CompilationUnit root ) { } private int getPackageStatementEndPos ( CompilationUnit root ) { } public String toString ( ) { } private static final class ImportDeclEntry { private String elementName ; private IRegion sourceRange ; private final boolean isStatic ; public ImportDeclEntry ( String elementName , boolean isStatic , IRegion sourceRange ) { } public String getElementName ( ) { } public int compareTo ( String fullName , boolean isStaticImport ) { } public String getSimpleName ( ) { } public boolean isOnDemand ( ) { } public boolean isStatic ( ) { } public boolean isNew ( ) { } public boolean isComment ( ) { } public IRegion getSourceRange ( ) { } } private static final class PackageEntry { public static ImportRewriteAnalyzer . PackageEntry createOnPlaceholderEntry ( String preferenceOrder ) { } private String name ; private ArrayList importEntries ; private String group ; private boolean isStatic ; public PackageEntry ( ) { } public PackageEntry ( String name , String group , boolean isStatic ) { } public boolean isStatic ( ) { } public int compareTo ( String otherName , boolean isOtherStatic ) { } public void sortIn ( ImportRewriteAnalyzer . ImportDeclEntry imp ) { } public void add ( ImportRewriteAnalyzer . ImportDeclEntry imp ) { } public ImportRewriteAnalyzer . ImportDeclEntry find ( String simpleName ) { } public boolean remove ( String fullName , boolean isStaticImport ) { } public void removeAllNew ( Set onDemandConflicts ) { } public ImportRewriteAnalyzer . ImportDeclEntry getImportAt ( int index ) { } public boolean hasStarImport ( int threshold , Set explicitImports ) { } public int getNumberOfImports ( ) { } public String getName ( ) { } public String getGroupID ( ) { } public void setGroupID ( String groupID ) { } public boolean isSameGroup ( ImportRewriteAnalyzer . PackageEntry other ) { } public ImportRewriteAnalyzer . ImportDeclEntry getLast ( ) { } public boolean isComment ( ) { } public boolean isDefaultPackage ( ) { } public String toString ( ) { } } public String [ ] getCreatedImports ( ) { } public String [ ] getCreatedStaticImports ( ) { } }

Fix:
int startPos = first . getStartPosition ( ) ;