New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“String index out of range” error with bracket handling in the editor #1940

Closed
SableRaf opened this Issue Jul 4, 2013 · 7 comments

Comments

Projects
None yet
5 participants
@SableRaf

SableRaf commented Jul 4, 2013

While trying to select a piece of code I got this error:

Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 910
    at java.lang.String.charAt(String.java:686)
    at processing.app.syntax.Brackets.findMatchingBracket(Brackets.java:69)
    at processing.app.syntax.JEditTextArea.updateBracketHighlight(JEditTextArea.java:2038)
    at processing.app.syntax.JEditTextArea.select(JEditTextArea.java:1235)
    at processing.app.syntax.JEditTextArea$DragHandler.mouseDragged(JEditTextArea.java:2336)
    at java.awt.AWTEventMulticaster.mouseDragged(AWTEventMulticaster.java:302)
    at java.awt.Component.processMouseMotionEvent(Component.java:6430)
    at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3293)
    at java.awt.Component.processEvent(Component.java:6151)
    at java.awt.Container.processEvent(Container.java:2083)
    at java.awt.Component.dispatchEventImpl(Component.java:4744)
    at java.awt.Container.dispatchEventImpl(Container.java:2141)
    at java.awt.Component.dispatchEvent(Component.java:4572)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4297)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.java:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489)
    at java.awt.Component.dispatchEvent(Component.java:4572)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:663)
    at java.awt.EventQueue$2.run(EventQueue.java:661)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:677)
    at java.awt.EventQueue$3.run(EventQueue.java:675)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Jul 4, 2013

Precisely, I was selecting the text inside the parenthesis, from right to left, and the error appeared each time the cursor crossed the 'f' of the first float.

//
void newKnot(float x, float y, float weight) {
}

After removing the empty comment on top, the error disappeared, but putting it back doesn't make the error appear again.

SableRaf commented Jul 4, 2013

Precisely, I was selecting the text inside the parenthesis, from right to left, and the error appeared each time the cursor crossed the 'f' of the first float.

//
void newKnot(float x, float y, float weight) {
}

After removing the empty comment on top, the error disappeared, but putting it back doesn't make the error appear again.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jul 19, 2013

Member

I don't doubt this is happening, but I can't get it to reproduce with nothing in a sketch but what you have there. Are you able to make it happen repeatedly?

Member

benfry commented Jul 19, 2013

I don't doubt this is happening, but I can't get it to reproduce with nothing in a sketch but what you have there. Are you able to make it happen repeatedly?

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Jul 21, 2013

It was happening systematically until I made a change in the code (removing the empty comment). I'm unable to reproduce it.

SableRaf commented Jul 21, 2013

It was happening systematically until I made a change in the code (removing the empty comment). I'm unable to reproduce it.

@SableRaf

This comment has been minimized.

Show comment
Hide comment
@SableRaf

SableRaf Jul 21, 2013

I guess it is some error linked to the code that detects the closing parenthesis. Sorry I can't be more helpful.

SableRaf commented Jul 21, 2013

I guess it is some error linked to the code that detects the closing parenthesis. Sorry I can't be more helpful.

@GKFX

This comment has been minimized.

Show comment
Hide comment
@GKFX

GKFX Dec 3, 2013

Contributor

How about validating "offsets" in findMatchingBracket() in Brackets.java? We already do

  if (offsets == null)
      parse(text);

but we could do

for (Integer i : offsets) {
  if (i >= text.length())
    parse(text);
}

or something of the sort. (I don't fully understand Brackets.java myself, but this is just an idea.)
The issue is

      final int offset = offsets.get(p);
      final char c = text.charAt(offset);
Contributor

GKFX commented Dec 3, 2013

How about validating "offsets" in findMatchingBracket() in Brackets.java? We already do

  if (offsets == null)
      parse(text);

but we could do

for (Integer i : offsets) {
  if (i >= text.length())
    parse(text);
}

or something of the sort. (I don't fully understand Brackets.java myself, but this is just an idea.)
The issue is

      final int offset = offsets.get(p);
      final char c = text.charAt(offset);
@fiawn

This comment has been minimized.

Show comment
Hide comment
@fiawn

fiawn Mar 25, 2016

Same problem is happening here (Windows 10, Processing 3.0.2):

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:418)
    at java.util.ArrayList.get(ArrayList.java:431)
    at processing.app.syntax.Brackets.findMatchingBracket(Brackets.java:54)
    at processing.app.syntax.JEditTextArea.updateBracketHighlight(JEditTextArea.java:2083)
    at processing.app.syntax.JEditTextArea.select(JEditTextArea.java:1273)
    at processing.app.syntax.JEditTextArea.setCaretPosition(JEditTextArea.java:1209)
    at processing.app.syntax.InputHandler$prev_line.actionPerformed(InputHandler.java:971)
    at processing.app.syntax.InputHandler.executeAction(InputHandler.java:310)
    at processing.app.syntax.DefaultInputHandler.keyPressed(DefaultInputHandler.java:220)
    at processing.app.syntax.PdeInputHandler.keyPressed(PdeInputHandler.java:221)
    at processing.app.syntax.JEditTextArea.processKeyEvent(JEditTextArea.java:1992)
    at processing.mode.java.pdex.JavaTextArea.processKeyEvent(JavaTextArea.java:221)

fiawn commented Mar 25, 2016

Same problem is happening here (Windows 10, Processing 3.0.2):

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:418)
    at java.util.ArrayList.get(ArrayList.java:431)
    at processing.app.syntax.Brackets.findMatchingBracket(Brackets.java:54)
    at processing.app.syntax.JEditTextArea.updateBracketHighlight(JEditTextArea.java:2083)
    at processing.app.syntax.JEditTextArea.select(JEditTextArea.java:1273)
    at processing.app.syntax.JEditTextArea.setCaretPosition(JEditTextArea.java:1209)
    at processing.app.syntax.InputHandler$prev_line.actionPerformed(InputHandler.java:971)
    at processing.app.syntax.InputHandler.executeAction(InputHandler.java:310)
    at processing.app.syntax.DefaultInputHandler.keyPressed(DefaultInputHandler.java:220)
    at processing.app.syntax.PdeInputHandler.keyPressed(PdeInputHandler.java:221)
    at processing.app.syntax.JEditTextArea.processKeyEvent(JEditTextArea.java:1992)
    at processing.mode.java.pdex.JavaTextArea.processKeyEvent(JavaTextArea.java:221)
@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 8, 2016

Member

@fiawn That's not the same error or error message. Please file a new bug if you're seeing something like that.

Member

benfry commented May 8, 2016

@fiawn That's not the same error or error message. Please file a new bug if you're seeing something like that.

@processing processing locked and limited conversation to collaborators May 8, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.