Bug 15321

Summary: wordWrap throws StringArrayIndexOutOfBoundsExceptions
Product: Taglibs Reporter: Robert Taylor <rtaylor>
Component: String TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Robert Taylor 2002-12-12 16:54:11 UTC
wordWrap seems to be blowing up if the tag attempts to wrap a string that
contains a newline character as the 81st character. It will not blow up
if the 81st character is not a new line character.

This is my usage:
<string:wordWrap><bean:write name="form" property="body" 

Partial stack trace:
2120: java.lang.StringIndexOutOfBoundsException: String index out of range: 80
2120:   at java.lang.String.charAt(String.java:455)
2120:   at org.apache.taglibs.string.util.StringW.wordWrap(StringW.java:181)
2120:   at org.apache.taglibs.string.WordWrapTag.changeString
2120:   at org.apache.taglibs.string.StringTagSupport.doEndTag
Comment 1 Henri Yandell 2003-01-28 23:14:44 UTC
Ought to be fixed. Awaiting confirmation.
Comment 2 Felipe Leme 2004-03-10 04:20:37 UTC

Could you please try it again and, if the bug persists, reopen the bug providing
a better test case?

For instance, I created the following JSP page:

<%-- jsp page starts here --%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.0.1" prefix="str" %>


StringBuffer buffer = new StringBuffer(100);

for ( int i=1; i<=80; i++ ) {
   buffer.append( (char) i%10 );

String word = request.getParameter("word");
if ( word == null ) {
   word = "";

Word: <str:wordWrap><%=word%></str:wordWrap>
Length: <str:length><%=word%></str:length>


Word: <textarea cols="80" rows="10" name="word"><%=buffer.toString()%></textArea>
<input type="submit">
<%-- jsp page ends here --%>

And ran it with many inputs:


None of them caused an exception, so I think it might have been already fixed.