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 d47447acb..1d84f7d29 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 @@ -16,6 +16,7 @@ package org.springframework.batch.core.launch.support; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -273,6 +274,9 @@ public class CommandLineJobRunner { JobParameters jobParameters = jobParametersConverter.getJobParameters(StringUtils .splitArrayElementsIntoProperties(parameters, "=")); + Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), + "Invalid JobParameters " + Arrays.asList(parameters) + + ". If parameters are provided they should be in the form name=value (no whitespace)."); if (opts.contains("-restart")) { jobParameters = getLastFailedJobParameters(jobName); @@ -315,7 +319,7 @@ public class CommandLineJobRunner { JobParameters jobParameters = null; if (lastInstances.isEmpty()) { - throw new JobParametersNotFoundException("No job instance found for job=" + jobName); + throw new JobParametersNotFoundException("No job instance found for job=" + jobName); } while (!lastInstances.isEmpty()) { @@ -339,7 +343,7 @@ public class CommandLineJobRunner { start += count; lastInstances = jobExplorer.getJobInstances(jobName, start, count); - } + } if (jobParameters == null) { throw new JobParametersNotFoundException("No failed or stopped execution found for job=" + jobName); 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 765fb152a..c0882b5ad 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 @@ -120,6 +120,16 @@ public class CommandLineJobRunnerTests { assertEquals(new JobParameters(), StubJobLauncher.jobParameters); } + @Test + public void testWithInvalidParameters() throws Throwable { + String[] args = new String[] { jobPath, jobName, "foo" }; + CommandLineJobRunner.main(args); + assertEquals(1, StubSystemExiter.status); + String errorMessage = CommandLineJobRunner.getErrorMessage(); + assertTrue("Wrong error message: " + errorMessage, errorMessage + .contains("in the form name=value")); + } + @Test public void testRestart() throws Throwable { String[] args = new String[] { jobPath, "-restart", jobName };