From 3d30a64f0bfcb5f8dc857467ff7b1b4237371420 Mon Sep 17 00:00:00 2001 From: robokaso Date: Wed, 16 Apr 2008 08:09:50 +0000 Subject: [PATCH] RESOLVED - BATCH-589: StepExecutionResourceProxy's toString() leads to NPE added assertion delegate is not null in toString (similar to other methods) and removed the toString usage in FlatFileItemReader#setResource --- .../batch/core/resource/StepExecutionResourceProxy.java | 4 ++-- .../batch/item/file/FlatFileItemReader.java | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) 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 8c3340438..3d82f0f9a 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 @@ -291,9 +291,9 @@ public class StepExecutionResourceProxy extends StepExecutionListenerSupport imp * Delegates to the proxied Resource. */ 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(); } - - } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java index ab2402fee..5c83d76d2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java @@ -72,8 +72,6 @@ public class FlatFileItemReader extends ExecutionContextUserSupport implements I private Resource resource; - private String path; - private RecordSeparatorPolicy recordSeparatorPolicy; private String[] comments; @@ -181,7 +179,7 @@ public class FlatFileItemReader extends ExecutionContextUserSupport implements I } catch (RuntimeException ex) { // add current line count to message and re-throw int lineCount = getReader().getPosition(); - throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=" + path + throw new FlatFileParseException("Parsing error at line: " + lineCount + " in resource=" + resource.getDescription() + ", input=[" + line + "]", ex, line, lineCount); } } @@ -255,10 +253,6 @@ public class FlatFileItemReader extends ExecutionContextUserSupport implements I */ public void setResource(Resource resource) { this.resource = resource; - path = resource.toString(); - if (path.length() > 50) { - path = path.substring(0, 20) + "..." + path.substring(path.length()); - } } /**