Skip to content
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
Support empty comments in FlatFileItemReaderBuilder
Previously, if supplying empty comments or no comments to comments() of the FlatFileItemReaderBuilder, the comments would be ignored and instead use the default comments "#" provided by the FlatFileItemReader.

Resolves BATCH-2837
  • Loading branch information
drumonii committed Oct 4, 2019
commit a649ef68aff35f5e64891ae71c9bc50c65f75cef
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