Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-123

WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Labels:
      None

      Description

      Cloned from LANG-1397.


      This is the sample code.

      int max = Integer.MAX_VALUE;  // 2147483647
      WordUtils.wrap("foobar", max, "\n", true);
      

      and the error log.

      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -2147483648
      	at java.lang.String.substring(String.java:1967)
      	at org.apache.commons.lang3.text.WordUtils.wrap(WordUtils.java:291)
      	at org.apache.commons.lang3.text.WordUtils.wrap(WordUtils.java:179)
      

      Seems WordUtils in commons-text has the same bug. I will file it on commons-text side later.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ggregory Gary D. Gregory
                Reporter:
                tasanuma Takanobu Asanuma
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: