Skip to content

Commit

Permalink
fix IndexOutOfBoundsException in OrganizeImportsAction.doChooseImports
Browse files Browse the repository at this point in the history
When skipping an import except the last.

fixes #1996
  • Loading branch information
jukzi authored and noopur2507 committed Feb 6, 2025
1 parent 0aacc6d commit bb20580
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
*******************************************************************************/
package org.eclipse.jdt.ui.actions;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import java.text.Collator;

import org.eclipse.swt.widgets.Display;

import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -346,8 +345,8 @@ private IChooseImportQuery createChooseImportQuery(final JavaEditor editor) {
}

private TypeNameMatch[] doChooseImports(TypeNameMatch[][] openChoices, final ISourceRange[] ranges, final JavaEditor editor) {
List<TypeNameMatch> result= new ArrayList<>();
Display.getDefault().syncExec(() -> {
return Display.getDefault().syncCall(() -> {
List<TypeNameMatch> result= new ArrayList<>();
// remember selection
ISelection sel= editor.getSelectionProvider().getSelection();
ILabelProvider labelProvider= new TypeNameMatchLabelProvider(TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED);
Expand All @@ -366,23 +365,22 @@ protected void handleSelectionChanged() {
dialog.setElements(openChoices);
dialog.setComparator(ORGANIZE_IMPORT_COMPARATOR);
if (dialog.open() == Window.OK) {
Object[] res= dialog.getResult();
for (int i= 0; i < res.length; i++) {
Object[] array= (Object[]) res[i];
for (Object o : dialog.getResult()) {
Object[] array= (Object[]) o;
if (array.length > 0) {
result.add((TypeNameMatch) array[0]);
QualifiedTypeNameHistory.remember(result.get(i).getFullyQualifiedName());
TypeNameMatch match= (TypeNameMatch) array[0];
result.add(match);
QualifiedTypeNameHistory.remember(match.getFullyQualifiedName());
}
}
}
// restore selection
if (sel instanceof ITextSelection) {
ITextSelection textSelection= (ITextSelection) sel;
if (sel instanceof ITextSelection textSelection) {
editor.selectAndReveal(textSelection.getOffset(), textSelection.getLength());
}
fIsQueryShowing= false;
});
return result.toArray(new TypeNameMatch[0]);
return result;
}).toArray(TypeNameMatch[]::new);
}

private void doListSelectionChanged(int page, ISourceRange[] ranges, JavaEditor editor) {
Expand Down

0 comments on commit bb20580

Please sign in to comment.