Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: Release 1.5.1
-
Fix Version/s: Release 1.5.2, Release 1.6
-
Component/s: Tag Library
-
Labels:None
Description
I encountered the follow exception when using a <stripes:option /> tag in a JSP:
java.lang.NullPointerException
net.sourceforge.stripes.tag.InputTagSupport.isItemSelected(InputTagSupport.java:218)
net.sourceforge.stripes.tag.InputSelectTag.isOptionSelected(InputSelectTag.java:107)
net.sourceforge.stripes.tag.InputOptionTag.doEndInputTag(InputOptionTag.java:125)
net.sourceforge.stripes.tag.InputTagSupport.doEndTag(InputTagSupport.java:442)
After some investigation it appeared that the NPE was triggered by the custom formatter for an object returning null (in this case because the object's id field was empty). Updating the formatter to return empty string instead of null avoided the NPE, but it would be preferable for the tag to handle this case gracefully.
After some investigation it turns out that a formatter returning null causes problems in other places as well.
The reason is that Stripes expects a formatter to return a non-null value. This is (somewhat) stated in the Javadoc for Formatter: "If the value cannot be formatted because it is an inappropriate type, or because faulty pattern information was supplied, should fail loudly by throwing a RuntimeException or subclass thereof." I've added a further note stating that the method should never return null.
I think this is a valid requirement: asking a formatter to format a value to a String value, should not return null.