|
[
Permlink
| « Hide
]
Robert Kasanicky added a comment - 16/Apr/08 03:13 AM
Added assert in the toString method to get informative exception instead of NPE and removed the toString usage from FlatFileItemWriter#setResource (assuming the resource path is known at the time when resource is set just doesn't work).
I strongly disagree with this solution. It is nearly impossible to determine if and when toString is called. For example, somebody that uses AOP logging would be at a very high risk of accidently failing with exception.
I would like to see this issue reopened and toString implemented in such a way as to not throw an exception. E.g. return (delegate == null) ? "(" + filePattern + ")" : delegate.toString(); IMHO, trading one exception for another is the least effective resolution. All the methods in StepExecutionProxyResource throw exception if the resource is used before delegate is set, the reasoning I see is that you are in trouble if you are trying to use a proxy that proxies nothing.
However on a second look, I agree toString shouldn't really be throwing exceptions - reopening. Yes. I think the distinction is that all methods defined in the Resource interface should throw exception. Since toString is defined by Object, I wouldn't put it under that umbrella.
toString now returns filePattern as suggested when delegate is null.
it doesn't look like the FlatFileItemReader got changed back. Can we put that back? it was very useful.
I think how FlatFileItemReader used toString was a bug - when used with StepExecutionProxyResource you'd get the file pattern instead of the delegate.toString (you don't want that right?). The string was used only for putting together an exception message when line couldn't be parsed - resource.getDescription seems to be meant for such circumstances.
Ah, you're right. I just looked at the diff and the change you made makes perfect sense. Thanks for working on this Robert.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||