[ http://issues.apache.org/jira/browse/TAPESTRY-601?page=all ]
Howard M. Lewis Ship reassigned TAPESTRY-601:
---------------------------------------------
Assign To: Howard M. Lewis Ship
> EnhanceUtils needs null checks in the primitive unwrapper methods
> -----------------------------------------------------------------
>
> Key: TAPESTRY-601
> URL: http://issues.apache.org/jira/browse/TAPESTRY-601
> Project: Tapestry
> Type: Bug
> Components: Framework
> Versions: 4.0
> Reporter: Ben Pryor
> Assignee: Howard M. Lewis Ship
> Attachments: patch.txt
>
> The EnhanceUtils class contains a number of "primitive unwrapper" methods
> that are called from generated methods in enhanced classes. These methods
> take the form of:
> public static <primitive-type> toType(IBinding binding)
> {
> Type wrapped = (Type) binding.getObject(Type.class);
> return wrapped.primitiveValue();
> }
> The problem is that binding.getObject() can sometimes return null, causing
> the wrapped.primitiveValue() to throw an NPE.
> This scenario happens when a container declares a property using the
> <property name="myname" /> syntax, and does not declare any abstract accessor
> methods for it. If this property is then bound to a component parameter, and
> that parameter has an abstract accessor method that returns a primitive type,
> the above scenario can occur.
> The reason is that to support a property declared as above, Tapestry creates
> a java.lang.Object field in the container class. This field gets the default
> Object value of null if no additional initialization is done to it. When
> this property is bound to a component parameter as described above, Tapestry
> generates calls to the appropriate primitive unwrapper method in the
> generated accessor.
> The fix is to null check the return from binding.getObject in the methods
> above, and to return the default value of the primitive type - 0, or false
> for boolean.
> Note that this was not an issue in Tapestry 3. The reason is that all
> <property-specifications> needed to have a type attribute, and the generated
> field was of that type. So if you were declaring a property that would be
> bound to a parameter that expected a primitive type, there was never a
> possibility of a null value.
> So again, the proposed fix for all the primitive unwrapper methods:
> public static <primitive-type> toType(IBinding binding)
> {
> Type wrapped = (Type) binding.getObject(Type.class);
> if (wrapped == null) return <default-primitive-value>;
> return wrapped.primitiveValue();
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]