Skip to content

BATCH-2837: Support empty or no comments in FlatFileItemReaderBuilder #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,7 @@ else if(this.fieldSetMapper != null) {
}

reader.setLinesToSkip(this.linesToSkip);

if(!this.comments.isEmpty()) {
reader.setComments(this.comments.toArray(new String[this.comments.size()]));
}
reader.setComments(this.comments.toArray(new String[this.comments.size()]));

reader.setSkippedLinesCallback(this.skippedLinesCallback);
reader.setRecordSeparatorPolicy(this.recordSeparatorPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,51 @@ public void testComments() throws Exception {
assertNull(reader.read());
}

@Test
public void testEmptyComments() throws Exception {
FlatFileItemReader<Foo> reader = new FlatFileItemReaderBuilder<Foo>()
.name("fooReader")
.resource(getResource("1,2,3\n4,5,6"))
.comments(new String[]{})
.delimited()
.names("first", "second", "third")
.targetType(Foo.class)
.build();

reader.open(new ExecutionContext());
Foo item = reader.read();
assertEquals(1, item.getFirst());
assertEquals(2, item.getSecond());
assertEquals("3", item.getThird());
item = reader.read();
assertEquals(4, item.getFirst());
assertEquals(5, item.getSecond());
assertEquals("6", item.getThird());
assertNull(reader.read());
}

@Test
public void testDefaultComments() throws Exception {
FlatFileItemReader<Foo> reader = new FlatFileItemReaderBuilder<Foo>()
.name("fooReader")
.resource(getResource("1,2,3\n4,5,6"))
.delimited()
.names("first", "second", "third")
.targetType(Foo.class)
.build();

reader.open(new ExecutionContext());
Foo item = reader.read();
assertEquals(1, item.getFirst());
assertEquals(2, item.getSecond());
assertEquals("3", item.getThird());
item = reader.read();
assertEquals(4, item.getFirst());
assertEquals(5, item.getSecond());
assertEquals("6", item.getThird());
assertNull(reader.read());
}

@Test
public void testPrototypeBean() throws Exception {
BeanFactory factory = new AnnotationConfigApplicationContext(Beans.class);
Expand Down