Project

General

Profile

Bug #10344

StringIndexOutOfBoundsException in editor when deleting text after complex operations

Added by Ionut-Mihai Simioniuc 12 months ago. Updated 12 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
Due date:
% Done:

0%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:

Related issues

Related to User Interface - Bug #10085: Fix offset cursor when pressing (CTRL+V) in an editor Test

History

#1 Updated by Ionut-Mihai Simioniuc 12 months ago

  • Subject changed from StringIndexOutOfBoundsException in Editor when deleting text to StringIndexOutOfBoundsException in editor when deleting text after complex operations

#2 Updated by Ionut-Mihai Simioniuc 12 months ago

Stack Trace:

Caused by: java.lang.StringIndexOutOfBoundsException: begin 221, end 161, length 239
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
    at java.base/java.lang.String.substring(String.java:2709)
    at com.goldencode.p2j.ui.client.gui.EditorGuiImpl$UndoableEditor.getChars(EditorGuiImpl.java:4196)
    at com.goldencode.p2j.ui.client.gui.EditorGuiImpl$UndoableEditor.recordDeletedText(EditorGuiImpl.java:4400)
    at com.goldencode.p2j.ui.client.gui.EditorGuiImpl$UndoableEditor.recordDeletedText(EditorGuiImpl.java:4349)
    at com.goldencode.p2j.ui.client.gui.EditorGuiImpl$UndoableEditor.processKey(EditorGuiImpl.java:4137)
    at com.goldencode.p2j.ui.client.gui.EditorGuiImpl.processKeyEvent(EditorGuiImpl.java:830)
    at com.goldencode.p2j.ui.client.widget.AbstractWidget$1.run(AbstractWidget.java:3319)
    at com.goldencode.p2j.ui.chui.ThinClient.eventBracket(ThinClient.java:19729)
    at com.goldencode.p2j.ui.chui.ThinClient.eventDrawingBracket(ThinClient.java:19671)
    at com.goldencode.p2j.ui.chui.ThinClient.independentEventDrawingBracket(ThinClient.java:19529)
    at com.goldencode.p2j.ui.client.widget.AbstractWidget.processSystemKey(AbstractWidget.java:3300)
    at com.goldencode.p2j.ui.chui.ThinClient.checkForSystemEvent(ThinClient.java:18755)
    at com.goldencode.p2j.ui.chui.ThinClient.waitForEvent(ThinClient.java:18550)
    at com.goldencode.p2j.ui.chui.ThinClient.waitForWorker(ThinClient.java:15336)
    at com.goldencode.p2j.ui.chui.ThinClient.lambda$waitForWorker$72(ThinClient.java:14849)
    at com.goldencode.p2j.ui.chui.ThinClient.lambda$doInteractive$92(ThinClient.java:20830)
    at com.goldencode.p2j.ui.chui.ThinClient.doInteractive(ThinClient.java:20802)
    at com.goldencode.p2j.ui.chui.ThinClient.doInteractive(ThinClient.java:20830)
    at com.goldencode.p2j.ui.chui.ThinClient.waitForWorker(ThinClient.java:14848)
    at com.goldencode.p2j.ui.chui.ThinClient.waitFor(ThinClient.java:14791)
    at com.goldencode.p2j.ui.chui.ThinClient.waitFor(ThinClient.java:14740)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:569)
    at com.goldencode.p2j.util.MethodInvoker.invoke(MethodInvoker.java:126)
    at com.goldencode.p2j.net.Dispatcher.processInbound(Dispatcher.java:808)
    at com.goldencode.p2j.net.Conversation.block(Conversation.java:418)
    at com.goldencode.p2j.net.Conversation.waitMessage(Conversation.java:344)
    at com.goldencode.p2j.net.Queue.transactImpl(Queue.java:1239)
    at com.goldencode.p2j.net.Queue.transact(Queue.java:687)
    at com.goldencode.p2j.net.BaseSession.transact(BaseSession.java:276)
    at com.goldencode.p2j.net.HighLevelObject.transact(HighLevelObject.java:221)
    at com.goldencode.p2j.net.RemoteObject$RemoteAccess.invokeCore(RemoteObject.java:1468)
    at com.goldencode.p2j.net.InvocationStub.invoke(InvocationStub.java:144)
    at jdk.proxy2/jdk.proxy2.$Proxy11.standardEntry(Unknown Source)
    at com.goldencode.p2j.main.ClientCore.start(ClientCore.java:476)
    at com.goldencode.p2j.main.ClientDriver.start(ClientDriver.java:287)
    at com.goldencode.p2j.main.CommonDriver.process(CommonDriver.java:522)
    at com.goldencode.p2j.main.ClientDriver.process(ClientDriver.java:171)

The bug seems to occur when mixing CTRL+V, CTRL+Z, CTRL+X, CTRL+C and a significant number of newlines. After performing these actions, pressing backspace can trigger the error. While not consistently reproducible, this sequence of actions has led to client crashes.

Root Cause :

   private String getChars(int startOffset, int endOffset)
      {
         // transform them to 0-based indexes
         startOffset = Math.max(startOffset - 1, 0);
         endOffset   = Math.min(endOffset - 1, editor.contentLength());

         String content = editor.resolveContent();
         String chars = content.substring(startOffset, endOffset);

         return chars;
      } 

in file EditorGuiImpl.

More precisely, the problem occurs at the line endOffset = Math.min(endOffset - 1, editor.contentLength());
because sometimes .contentLength() returns a value smaller than startOffset, resulting in startOffset > Math.min(endOffset - 1, editor.contentLength()), which causes a crash.

#3 Updated by Ionut-Mihai Simioniuc 12 months ago

  • Related to Bug #10085: Fix offset cursor when pressing (CTRL+V) in an editor added

Also available in: Atom PDF