ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 22007] New: - Copy task throws StringIndexOutOfBoundsException when a replacement token value is the empty string
Date Thu, 31 Jul 2003 00:09:36 GMT
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


Mime
View raw message