Skip to content

Default value of comment prefix in FlatFileItemReaderBuilder is inconsistent with FlatFileItemReader [BATCH-2862] #753

Closed
@spring-projects-issues

Description

@spring-projects-issues

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.


Referenced from: commits 38b43e8, d7ff73b, c2711d7, 87f040e

Backported to: 4.3.0.M1, 4.2.1, 4.1.3, 4.0.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions