commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan Escreet (JIRA)" <>
Subject [jira] Commented: (BEANUTILS-339) BeanUtilsBean.setProperty throws IllegalArgumentException if value is null
Date Sat, 21 Feb 2009 10:10:02 GMT


Alan Escreet commented on BEANUTILS-339:

That's precisely the line with the problem:
if ((value instanceof String) || (value == null))
This test only tests if the {{value}} is a String or is {{null}} before it tries to use a
converter on a String value. It does not, as the API doc states, treat it as a null String
if it is expecting a primitive value. There is no check here for expecting a primitive value.
It just assumes that any {{null}} is a String, which is a very strange assumption to make.

If I pass in a Comparator type value, I expect it to continue to be treated as a Comparator
type within BeanUtilsBean.
Why would I need to register a converter to convert a {{null}} String value back in to a {{null}}
Comparator value, which is actually what I passed in to the method in the first place? It
should remain as a {{null}} Comparator until I register a converter to convert it in to something

> BeanUtilsBean.setProperty throws IllegalArgumentException if value is null
> --------------------------------------------------------------------------
>                 Key: BEANUTILS-339
>                 URL:
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.8.0-BETA
>            Reporter: Alan Escreet
>            Priority: Blocker
>             Fix For: 1.8.0-BETA
> Line 1003-1004 conflicts with API doc: "If null is passed into a property expecting a
primitive value, then this will be converted as if it were a null string."
> Line 1003 only tests if the value is null and 1004 explicitly casts to a String. If a
bean has a field of any other type, i.e. java.util.Comparator, then this fails with:
> {{java.lang.IllegalArgumentException: Cannot invoke <myBean>.setComparator on bean
class 'class <myBean>' - argument type mismatch - had objects of type "java.lang.String"
but expected signature "java.util.Comparator"}}

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message