commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (BEANUTILS-321) [beanutils] wont recognize isXXX() properties returning Boolean Object
Date Wed, 09 Jul 2008 13:35:33 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12612097#action_12612097
] 

jwcarman edited comment on BEANUTILS-321 at 7/9/08 6:35 AM:
----------------------------------------------------------------

Thomas,

If you do something like:

{code}
if(myBean.isBooleanClass())
{
  // Do something here...
}
{code}

and the Boolean type booleanClass member variable is null, you'll get a null pointer in JDK5+,
because the auto-unboxing feature tries to call booleanClass.booleanValue() to unbox it. 
If you try to do this in pre-JD5, it won't compile (because Boolean isn't of type boolean,
so you can't use it as your conditional in your if statement).

And, for the record, I do understand your point.  I've actually encountered this before. 
I don't recall the exact situation, but I'm sure I just renamed my "getter."  Have you tried
providing a "get" version of your accessor along with the "is" version?  That should probably
solve your problem, I think (if you're ok with the potential NPE when accessing the "is" version
in a conditional that is).

      was (Author: jwcarman):
    Thomas,

If you do something like:

{code}
if(myBean.isBooleanClass())
{
  // Do something here...
}
{code}

and the Boolean type booleanClass member variable is null, you'll get a null pointer in JDK5+,
because the auto-unboxing feature tries to call booleanClass.booleanValue() to unbox it. 
If you try to do this in pre-JD5, it won't compile (because Boolean isn't of type boolean,
so you can't use it as your conditional in your if statement)
  
> [beanutils] wont recognize isXXX() properties returning Boolean Object
> ----------------------------------------------------------------------
>
>                 Key: BEANUTILS-321
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-321
>             Project: Commons BeanUtils
>          Issue Type: New Feature
>    Affects Versions: 1.7.0
>            Reporter: thomas menzel
>
> it seems that an isXXX() style property returning an java.lang.Boolean Object is NOT
recognized as the getter peoperty -- at least it wont copy it.
> Hence, the test case below will fail.
> I suggest to handle these props as well, as for a user of BeanUtils this was/is quite
surprising to me -- and probably others.
> Thx
> {code:java}
> /**
>  * @author tmenzel
>  * 
>  */
> public class BeanUtilsTest extends TestCase {
>   private class FooBean {
>     Boolean booleanClass;
>     boolean booleanPrimitive;
>     public Boolean isBooleanClass() {
>       return booleanClass;
>     }
>     public void setBooleanClass(Boolean booleanClass) {
>       this.booleanClass = booleanClass;
>     }
>     public boolean isBooleanPrimitive() {
>       return booleanPrimitive;
>     }
>     public void setBooleanPrimitive(boolean booleanPrimitive) {
>       this.booleanPrimitive = booleanPrimitive;
>     }
>   }
>   public void testCopyBooleanProps() throws Exception {
>     FooBean a = new FooBean();
>     a.setBooleanClass(false);
>     a.setBooleanPrimitive(false);
>     FooBean b = new FooBean();
>     b.setBooleanClass(true);
>     b.setBooleanPrimitive(true);
>     BeanUtils.copyProperties(a, b);
>     assertEquals(a.isBooleanPrimitive(), b.isBooleanPrimitive());
>     assertEquals(a.isBooleanClass(), b.isBooleanClass());
>   }
> }
> {code}

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


Mime
View raw message