Closed
Description
Mahmoud Ben Hassine opened BATCH-2862 and commented
The default value of comment prefix is "#" in FlatFileItemReader
but empty list in FlatFileItemReaderBuilder
. This means we need to explicitly add this prefix when using the builder while it is implicit when creating the reader without the builder. Here are two tests that explain the issue:
@Test
public void testDefaultCommentsWithoutBuilder() throws Exception {
FlatFileItemReader<String> reader = new FlatFileItemReader<>();
reader.setName("itemReader");
reader.setResource(getResource("line1\n#line2"));
reader.setLineMapper(new PassThroughLineMapper());
reader.open(new ExecutionContext());
String item = reader.read();
assertEquals("line1", item);
assertNull(reader.read()); // line "#line2" is ignored by default
reader.close();
}
@Test
public void testDefaultCommentsWithBuilder() throws Exception {
FlatFileItemReader<String> reader = new FlatFileItemReaderBuilder<String>()
.name("itemReader")
.resource(getResource("line1\n#line2"))
.lineMapper(new PassThroughLineMapper())
.build();
reader.open(new ExecutionContext());
String item = reader.read();
assertEquals("line1", item);
assertNull(reader.read()); // line "#line2" should be ignored by default, but it is not the case
reader.close();
}
testDefaultCommentsWithoutBuilder
passes while testDefaultCommentsWithBuilder
fails. This is inconsistent, a builder should have the same defaults as the object it creates.