Bug 9762 - <linecontains> filter erroneously filters out adjacent matches
Summary: <linecontains> filter erroneously filters out adjacent matches
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.5
Hardware: All All
: P3 major (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-11 00:22 UTC by James Clingenpeel
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Clingenpeel 2002-06-11 00:22:37 UTC
If there are two adjacent lines which should be matched by a <linecontains> 
filter, the second line is missed.  This bug occurs in version 1.5Beta2 but not 
in version 1.5Beta1.

You can duplicate this bug with the following files:
---------- begin build.xml ----------
<project name="bug" default="test">
	<target name="test">
		<loadproperties srcfile="test.props">
			<filterchain>
				<linecontains>
					<contains value="foo."/>
				</linecontains>
			</filterchain>
		</loadproperties>
		<echo message="foo.bar = ${foo.bar}"/>
		<echo message="foo.baz = ${foo.baz}"/>
	</target>
</project>
---------- end build.xml ----------

---------- begin test.props ----------
foo.bar=1
foo.baz=2
baz.bletch=3
---------- end test.props ----------

This example should load the properties foo.bar and foo.baz, but it does not 
load foo.baz.

I looked at the source code for LineContains.java and found the following code 
in the read() method.  This snippet is executed when looking for the next 
matching line.  The comments are mine.

line = readLine();
while((line != null) && (goodLine == null)) {
    // [code which sets goodLine to null if line doesn't match]
    line = readLine(); // if we matched a line, this readLine() will be lost!
}
if (goodLine != null) {
    line = goodLine;
    return read();
};

a quick fix is to change the while loop like this:

while((line != null) && (goodLine == null)) {
    // [code which sets goodLine to null if line doesn't match]
    if (goodLine == null) {
        line = readLine(); 
    }
}
Comment 1 Stefan Bodewig 2002-06-12 09:23:28 UTC
Supposed to be fixed in the 1.5 branch, please try with the latest build
from <http://cvs.apache.org/~bodewig/gump/ant1.5beta/>.