diff --git a/build.gradle b/build.gradle index 1e95089a0..66503fc77 100644 --- a/build.gradle +++ b/build.gradle @@ -156,9 +156,9 @@ subprojects { subproject -> destinationFile = file("$buildDir/jacoco.exec") } - testLogging { - showStandardStreams = true - } +// testLogging { +// showStandardStreams = true +// } } task sourcesJar(type: Jar) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java index c59701ec1..7255fd0ce 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java @@ -534,7 +534,7 @@ public class CommandLineJobRunner { if (System.in.available() > 0) { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line = " "; - while (StringUtils.hasLength(line)) { + while (line != null) { if (!line.startsWith("#") && StringUtils.hasText(line)) { logger.debug("Stdin arg: " + line); newargs.add(line); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java index 4f66cf220..aae6fb5c9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java @@ -15,9 +15,22 @@ */ package org.springframework.batch.core.launch.support; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Properties; +import java.util.Set; + import org.junit.After; import org.junit.Before; import org.junit.Test; + import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; @@ -37,18 +50,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.ClassUtils; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /** * @author Lucas Ward * @@ -180,6 +181,28 @@ public class CommandLineJobRunnerTests { assertEquals(0, StubSystemExiter.status); assertEquals(2, StubJobLauncher.jobParameters.getParameters().size()); } + + @Test + public void testWithStdinCommandLineWithEmptyLines() throws Throwable { + System.setIn(new InputStream() { + char[] input = (jobPath+"\n"+jobName+"\nfoo=bar\n\nspam=bucket\n\n").toCharArray(); + + int index = 0; + + @Override + public int available() { + return input.length - index; + } + + @Override + public int read() { + return index