Hi,
I just came up to following situation:
BindingModel.java:
The line "errors.add(new FieldError(objectName, (String) message.getSource(), message.getText()));" is likely to throw a ClassCastException each time when source of message isn't a String...Code:private List [More ...] toErrors(Message[] messages) { if (messages == null || messages.length == 0) { return Collections.EMPTY_LIST; } ArrayList errors = new ArrayList(messages.length); for (int i = 0; i < messages.length; i++) { Message message = messages[i]; if (message.getSource() == null) { errors.add(new ObjectError(objectName, message.getText())); } else { // ClassCastException from casting to String errors.add(new FieldError(objectName, (String) message.getSource(), message.getText())); } } return Collections.unmodifiableList(errors); }
It is possible since Message defines getSource() as:
So it is not forbidden to set source to something different than String...Code:public Object getSource() { return source; }
Wouldn't it be better to make a toString() there?
I found this actually when calling toString() on BindingModel (AbstractErrors.toString()->getErrorCount()->getAllErrors()->getGlobalErrors()->toErrors()->bang!) - know that this is a corner case... but it sometimes makes debugging really nasty.


) - know that this is a corner case... but it sometimes makes debugging really nasty.
Reply With Quote