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 3d82f0f9a..550533107 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 @@ -288,12 +288,10 @@ public class StepExecutionResourceProxy extends StepExecutionListenerSupport imp } /** - * Delegates to the proxied Resource. + * Delegates to the proxied Resource if set, otherwise returns the {@link #filePattern}. */ public String toString() { - Assert.state(delegate != null, "The delegate resource has not been initialised. " - + "Remember to register this object as a StepListener."); - return delegate.toString(); + return (delegate == null) ? filePattern : delegate.toString(); } } 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 2535ee974..fff9988df 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 @@ -133,6 +133,16 @@ public class StepExecutionResourceProxyTests extends TestCase { resource.beforeStep(stepExecution); assertEquals("to-string-test-resource", resource.toString()); } + + /** + * If delegate is not set toString returns the filePattern. + */ + public void testToStringWithNullDelegate() { + resource = new StepExecutionResourceProxy(); + String filePattern = "arbitrary pattern"; + resource.setFilePattern("arbitrary pattern"); + assertEquals(filePattern, resource.toString()); + } private void doTestPathName(String filename, String path) throws Exception, IOException { String returnedPath = resource.getFile().getAbsolutePath();