You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jeremy Mawson (JIRA)" <ji...@apache.org> on 2008/07/01 03:56:45 UTC

[jira] Commented: (BEANUTILS-317) BeanUtils.setProperty does not seem to be able to set a null value on a java.lang.Integer

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

Jeremy Mawson commented on BEANUTILS-317:
-----------------------------------------

I'm having trouble with this also.

I am trying to set a null Integer onto an Integer, but BeanUtilsBean is defaulting the value to 0, which has negative side-effects for my app.

The BeanUtilsBean.copyProperty(Object, String, Object) method attempt to find and use a Converter in all circumstances. It probably should only do this if the source and target field types are different.


> BeanUtils.setProperty does not seem to be able to set a null value on a java.lang.Integer
> -----------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-317
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-317
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.6, 1.6.1, 1.7.0, 1.8.0-BETA
>         Environment: Java 1.6
>            Reporter: Tj Zecca
>
> I get the following unexpected results:
> INITIAL STATE: null
> AFTER SETTER: 5
> AFTER BeanUtils.setProperty: 0
> Using the following code:
> public static void main(String[] args) {
>     SimpleBean bean = new SimpleBean();
>     System.out.println("INITIAL STATE: " + bean.getNum());
>     bean.setNum(new Integer(5));
>     System.out.println("AFTER SETTER: " + bean.getNum());
>     try {
>         BeanUtils.setProperty(bean, "num", null);
>         System.out.println("AFTER BeanUtils.setProperty: " + bean.getNum());
>     } catch (Exception e) {
>         e.printStackTrace();
>     }
> }
> public class SimpleBean {
>     private Integer num;
>     public Integer getNum() {
>         return this.num;
>     }
>     public void setNum(Integer num) {
>         this.num = num;
>     }
> }
> PS. I have also tested with the Boolean primitive wrapper and it does not set null either.

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