diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java index 7e58f0d41..ebd7735f5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java @@ -284,7 +284,14 @@ public class StepExecutionResourceProxy extends StepExecutionListenerSupport imp String jobName = execution.getJobExecution().getJobInstance().getJobName(); Properties properties = jobParametersConverter.getProperties(execution.getJobExecution().getJobInstance() .getJobParameters()); - delegate = resourceLoader.getResource(createFileName(jobName, stepName, properties)); + String fileName = createFileName(jobName, stepName, properties); + if(fileName.indexOf("%") > -1){ + //if a % is still left in the fileName after matching, we have to assume that either no job parameter was found, + //or an invalid path was used. + throw new IllegalStateException("Invalid file pattern provided: [" + this.filePattern + "], tokens still remain after parameter matching: [" + + fileName + "]"); + } + delegate = resourceLoader.getResource(fileName); } /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/StepExecutionResourceProxyTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/StepExecutionResourceProxyTests.java index 88effa843..beaa951b4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/StepExecutionResourceProxyTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/StepExecutionResourceProxyTests.java @@ -141,6 +141,22 @@ public class StepExecutionResourceProxyTests extends TestCase { resource.setFilePattern("arbitrary pattern"); assertEquals(filePattern, resource.toString()); } + + public void testNonExistentJobParameter() throws Exception{ + + resource.setFilePattern("foo/data/%JOB_NAME%/%non.key%-foo"); + jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam") + .toJobParameters(), "testJob"); + JobExecution jobExecution = new JobExecution(jobInstance); + Step step = new StepSupport("bar"); + try{ + resource.beforeStep(jobExecution.createStepExecution(step)); + fail(); + } + catch(Exception ex){ + //expected, if there isn't a JobParameter for that key, it should throw an exception + } + } private void doTestPathName(String filename, String path) throws Exception, IOException { String returnedPath = resource.getFile().getAbsolutePath();