Skip to content

Commit abe29ad

Browse files
committed
Fix line tokenizer validation in FlatFileItemReaderBuilder
Resolves #766
1 parent 6c70347 commit abe29ad

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -454,7 +454,7 @@ public FlatFileItemReader<T> build() {
454454

455455
DefaultLineMapper<T> lineMapper = new DefaultLineMapper<>();
456456

457-
if(this.lineTokenizer != null && this.fieldSetMapper != null) {
457+
if(this.lineTokenizer != null) {
458458
lineMapper.setLineTokenizer(this.lineTokenizer);
459459
}
460460
else if(this.fixedLengthBuilder != null) {

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -519,6 +519,24 @@ public void testCustomEncoding() {
519519
assertEquals(encoding, ReflectionTestUtils.getField(reader, "encoding"));
520520
}
521521

522+
@Test
523+
public void testErrorMessageWhenNoFieldSetMapperIsProvided() {
524+
try {
525+
new FlatFileItemReaderBuilder<Foo>()
526+
.name("fooReader")
527+
.resource(getResource("1;2;3"))
528+
.lineTokenizer(line -> new DefaultFieldSet(line.split(";")))
529+
.build();
530+
} catch (IllegalStateException exception) {
531+
String exceptionMessage = exception.getMessage();
532+
if (exceptionMessage.equals("No LineTokenizer implementation was provided.")) {
533+
fail("Error message should not be 'No LineTokenizer implementation was provided.'" +
534+
" when a LineTokenizer is provided");
535+
}
536+
assertEquals("No FieldSetMapper implementation was provided.", exceptionMessage);
537+
}
538+
}
539+
522540
private Resource getResource(String contents) {
523541
return new ByteArrayResource(contents.getBytes());
524542
}

0 commit comments

Comments
 (0)