Uploaded image for project: 'Pivot'
  1. Pivot
  2. PIVOT-954

Double click in empty TextArea causes exception

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.4, 2.1
    • Fix Version/s: 2.1, 2.0.5
    • Component/s: wtk
    • Environment:
      All

      Description

      Start with an empty TextArea, then double click anywhere (which normally would select the current word), there will be basically an assertion error from here:
      java.lang.IndexOutOfBoundsException: index: index (-1) < min (0)
      at org.apache.pivot.wtk.Component.indexBoundsCheck(Component.java:2861)
      at org.apache.pivot.wtk.TextArea.getCharacterAt(TextArea.java:904)
      at org.apache.pivot.wtk.skin.TextAreaSkin.selectSpan(TextAreaSkin.java:969)
      at org.apache.pivot.wtk.skin.TextAreaSkin.mouseClick(TextAreaSkin.java:1023)

      The underlying problem is trying to get the character at offset -1 in the document.

      It could also occur in any document in which the first line is empty, and trying to double click there (with a slightly different stack trace):
      java.lang.IndexOutOfBoundsException: index: index (-1) < min (0)
      at org.apache.pivot.wtk.Component.indexBoundsCheck(Component.java:2861)
      at org.apache.pivot.wtk.TextArea.getCharacterAt(TextArea.java:904)
      at org.apache.pivot.wtk.skin.TextAreaSkin.selectSpan(TextAreaSkin.java:974)
      at org.apache.pivot.wtk.skin.TextAreaSkin.mouseClick(TextAreaSkin.java:1023)

      (This is from the "trunk" version).

        Activity

        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Tested the fail cases in our application.

        Show
        rwhitcomb Roger Whitcomb added a comment - Tested the fail cases in our application.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Checking into trunk:
        Sending wtk\src\org\apache\pivot\wtk\skin\TextAreaSkin.java
        Transmitting file data .
        Committed revision 1611829.

        Merging into branches/2.0.x:
        Sending .
        Sending wtk\src\org\apache\pivot\wtk\skin\TextAreaSkin.java
        Transmitting file data .
        Committed revision 1611832.

        Show
        rwhitcomb Roger Whitcomb added a comment - Checking into trunk: Sending wtk\src\org\apache\pivot\wtk\skin\TextAreaSkin.java Transmitting file data . Committed revision 1611829. Merging into branches/2.0.x: Sending . Sending wtk\src\org\apache\pivot\wtk\skin\TextAreaSkin.java Transmitting file data . Committed revision 1611832.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Here is the diff that fixes the problem:
        Index: wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
        ===================================================================
        — wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (revision 1611499)
        +++ wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (working copy)
        @@ -966,11 +966,17 @@
        int rowLength = textArea.getRowLength(start);
        if (start - rowStart >= rowLength) {
        start = rowStart + rowLength - 1;
        + if (start < 0)

        { + return; + }

        char ch = textArea.getCharacterAt(start);
        if (ch == '\r' || ch == '\n')

        { start--; }

        }
        + if (start < 0)

        { + return; + }

        char ch = textArea.getCharacterAt(start);
        int selectionStart = start;
        int selectionLength = 1;

        Show
        rwhitcomb Roger Whitcomb added a comment - Here is the diff that fixes the problem: Index: wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java =================================================================== — wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (revision 1611499) +++ wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (working copy) @@ -966,11 +966,17 @@ int rowLength = textArea.getRowLength(start); if (start - rowStart >= rowLength) { start = rowStart + rowLength - 1; + if (start < 0) { + return; + } char ch = textArea.getCharacterAt(start); if (ch == '\r' || ch == '\n') { start--; } } + if (start < 0) { + return; + } char ch = textArea.getCharacterAt(start); int selectionStart = start; int selectionLength = 1;

          People

          • Assignee:
            rwhitcomb Roger Whitcomb
            Reporter:
            rwhitcomb Roger Whitcomb
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development