eclipse-jdt / eclipse.jdt.ui

Eclipse Public License 2.0
37 stars 92 forks source link

[Externalize Strings Dialog] StringIndexOutOfBoundsException #1803

Open wolfgang-ch opened 2 days ago

wolfgang-ch commented 2 days ago

The original issue is from Aug 1, 2024 https://github.com/eclipse-platform/.github/issues/219, it is now moved here because of https://github.com/eclipse-platform/.github/issues/219#issuecomment-2488250785

Steps to reproduce

Open the "Externalize Strings..." dialog with this simple class

public class NLTest {

   public static final String SYMBOL_AMPERSAND = "&";  //$NON-NLS-1$
   public static final String SYMBOL_QUOTA     = "\""; //$NON-NLS-1$
}

I expected: The NLS dialog should open

But got: The NLS dialog did not opened

With this workaround the NLS dialog opens

public class NLTest {

   public static final String SYMBOL_AMPERSAND = "&";                                       //$NON-NLS-1$
   public static final String SYMBOL_QUOTA     = new StringBuilder().append('"').toString();
}

Here is some relevant log output

From the terminal

java.lang.StringIndexOutOfBoundsException: begin 3, end 0, length 3
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
        at java.base/java.lang.String.substring(String.java:2709)
        at org.eclipse.jdt.internal.corext.refactoring.nls.NLSHint.stripQuotes(NLSHint.java:266)
        at org.eclipse.jdt.internal.corext.refactoring.nls.NLSHint.createSubstitutions(NLSHint.java:221)
        at org.eclipse.jdt.internal.corext.refactoring.nls.NLSHint.<init>(NLSHint.java:106)
        at org.eclipse.jdt.internal.corext.refactoring.nls.NLSRefactoring.<init>(NLSRefactoring.java:92)
        at org.eclipse.jdt.internal.corext.refactoring.nls.NLSRefactoring.create(NLSRefactoring.java:113)
        at org.eclipse.jdt.internal.ui.refactoring.nls.ExternalizeWizard.lambda$0(ExternalizeWizard.java:84)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
        at org.eclipse.jdt.internal.ui.refactoring.nls.ExternalizeWizard.open(ExternalizeWizard.java:81)
        at org.eclipse.jdt.ui.actions.ExternalizeStringsAction.run(ExternalizeStringsAction.java:191)
        at org.eclipse.jdt.ui.actions.ExternalizeStringsAction.run(ExternalizeStringsAction.java:156)
        at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
        at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:252)
        at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
        at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:581)
        at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:415)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4326)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1174)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4124)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3712)

Tested under this environment:

nettozahler commented 1 day ago

I can deliver a PR for this. One question first: do we have a utility class where I can add a method like this: public static boolean isTextBlock(String str)