You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2003/07/31 02:09:36 UTC

DO NOT REPLY [Bug 22007] New: - Copy task throws StringIndexOutOfBoundsException when a replacement token value is the empty string

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22007>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22007

Copy task throws StringIndexOutOfBoundsException when a replacement token value is the empty string

           Summary: Copy task throws StringIndexOutOfBoundsException when a
                    replacement token value is the empty string
           Product: Ant
           Version: 1.5.3
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core tasks
        AssignedTo: dev@ant.apache.org
        ReportedBy: magellan94@hotmail.com


A copy task that uses replacetokens to replace a key with an empty string 
throws a StringIndexOutOfBoundsException. For example:
    <copy tofile="${destfile}" file="${srcfile}">
      <filterchain>
        <replacetokens>
          <!-- replace @someKey@ with nothing -->
          <token key="someKey" value=""/>
        </replacetokens>
      </filterchain>
    </copy>

Workaround: Set the token value to a single space instead of the empty String:
          <!-- replace @someKey@ with a space " " -->
          <token key="someKey" value=" "/>

The bug is caused by this code in ReplaceTokens.java
    public final int read() throws IOException {
        // ...snip...
        // the call to String.charAt throws a StringIndexOutOfBoundsException

        if (replaceIndex != -1) { // line 159
            final int ch = replaceData.charAt(replaceIndex++);
            if (replaceIndex >= replaceData.length()) {
                replaceIndex = -1;
            }
            return ch;
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org