diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java index dd742d162..44696c16f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -474,7 +474,7 @@ public class FlatFileItemReaderBuilder { DefaultLineMapper lineMapper = new DefaultLineMapper<>(); - if(this.lineTokenizer != null && this.fieldSetMapper != null) { + if(this.lineTokenizer != null) { lineMapper.setLineTokenizer(this.lineTokenizer); } else if(this.fixedLengthBuilder != null) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java index 13acbb516..b1f8ef6b3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -524,6 +524,24 @@ public class FlatFileItemReaderBuilderTests { assertEquals(encoding, ReflectionTestUtils.getField(reader, "encoding")); } + @Test + public void testErrorMessageWhenNoFieldSetMapperIsProvided() { + try { + new FlatFileItemReaderBuilder() + .name("fooReader") + .resource(getResource("1;2;3")) + .lineTokenizer(line -> new DefaultFieldSet(line.split(";"))) + .build(); + } catch (IllegalStateException exception) { + String exceptionMessage = exception.getMessage(); + if (exceptionMessage.equals("No LineTokenizer implementation was provided.")) { + fail("Error message should not be 'No LineTokenizer implementation was provided.'" + + " when a LineTokenizer is provided"); + } + assertEquals("No FieldSetMapper implementation was provided.", exceptionMessage); + } + } + private Resource getResource(String contents) { return new ByteArrayResource(contents.getBytes()); }