[ 
https://issues.apache.org/jira/browse/BEANUTILS-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Niall Pemberton updated BEANUTILS-341:
--------------------------------------

    Description: 
BeanUtils.populate throws an exception (INoSuchMethodException -> 
nvocationTargetException) in case the bean is a nested class:

{code}
public class BeanUtilsTest extends TestCase {
        TestBean bean = null;
        Map<String, Object> params = null;

        @Override
        public void setUp() {
                bean = new TestBean();
                params = new HashMap<String, Object>();
        }
        
        public void testPopulate() {
                params.put("name", "Ivan");
                params.put("authentication", false);
                params.put("age", 24);
                try {
                        BeanUtils.populate(bean, params);
                } catch (Exception e) {
                        e.printStackTrace();
                }
                
                System.out.println(bean);
        }
        
        @Override
        public void tearDown() {
                this.bean = null;
                this.params = null;
        }
}

class TestBean {
        
        private String name;
        
        private int age;
        
        private boolean authenticated;
        
        public String getName() {
                return name;
        }
        
        public void setName(String name) {
                this.name = name;
        }
        
        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }

        public boolean isAuthenticated() {
                return authenticated;
        }
        
        public void setAuthenticated(boolean authenticated) {
                this.authenticated = authenticated;
        }
        
        @Override
        public String toString() {
                return ToStringBuilder.reflectionToString(this);
        }
}
{code}

{code}
java.lang.reflect.InvocationTargetException: Cannot set age
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1017)
        at 
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830)
        at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433)
        at 
com.alibaba.apache.BeanUtils.BeanUtilsTest.testPopulate(BeanUtilsTest.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at 
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter method 
in class 'class com.alibaba.apache.BeanUtils.TestBean'
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2128)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054)
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015)
        ... 22 more
cn.edu.ccnu.ivan.apache.beanutils.testb...@17590db[name=<null>,age=0,authenticated=false]
{code}

  was:
BeanUtils.populate throws an exception (INoSuchMethodException -> 
nvocationTargetException) in case the bean is a nested class:

public class BeanUtilsTest extends TestCase {
        TestBean bean = null;
        Map<String, Object> params = null;

        @Override
        public void setUp() {
                bean = new TestBean();
                params = new HashMap<String, Object>();
        }
        
        public void testPopulate() {
                params.put("name", "Ivan");
                params.put("authentication", false);
                params.put("age", 24);
                try {
                        BeanUtils.populate(bean, params);
                } catch (Exception e) {
                        e.printStackTrace();
                }
                
                System.out.println(bean);
        }
        
        @Override
        public void tearDown() {
                this.bean = null;
                this.params = null;
        }
}

class TestBean {
        
        private String name;
        
        private int age;
        
        private boolean authenticated;
        
        public String getName() {
                return name;
        }
        
        public void setName(String name) {
                this.name = name;
        }
        
        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }

        public boolean isAuthenticated() {
                return authenticated;
        }
        
        public void setAuthenticated(boolean authenticated) {
                this.authenticated = authenticated;
        }
        
        @Override
        public String toString() {
                return ToStringBuilder.reflectionToString(this);
        }
}

java.lang.reflect.InvocationTargetException: Cannot set age
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1017)
        at 
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830)
        at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433)
        at 
com.alibaba.apache.BeanUtils.BeanUtilsTest.testPopulate(BeanUtilsTest.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at 
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter method 
in class 'class com.alibaba.apache.BeanUtils.TestBean'
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2128)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948)
        at 
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054)
        at 
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015)
        ... 22 more
cn.edu.ccnu.ivan.apache.beanutils.testb...@17590db[name=<null>,age=0,authenticated=false]


> BeanUtils.populate throws an exception (INoSuchMethodException -> 
> nvocationTargetException)  in case the bean is a nested class
> -------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-341
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-341
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.8.0
>         Environment: jdk1.6
>            Reporter: Ivan.Huang
>
> BeanUtils.populate throws an exception (INoSuchMethodException -> 
> nvocationTargetException) in case the bean is a nested class:
> {code}
> public class BeanUtilsTest extends TestCase {
>       TestBean bean = null;
>       Map<String, Object> params = null;
>       @Override
>       public void setUp() {
>               bean = new TestBean();
>               params = new HashMap<String, Object>();
>       }
>       
>       public void testPopulate() {
>               params.put("name", "Ivan");
>               params.put("authentication", false);
>               params.put("age", 24);
>               try {
>                       BeanUtils.populate(bean, params);
>               } catch (Exception e) {
>                       e.printStackTrace();
>               }
>               
>               System.out.println(bean);
>       }
>       
>       @Override
>       public void tearDown() {
>               this.bean = null;
>               this.params = null;
>       }
> }
> class TestBean {
>       
>       private String name;
>       
>       private int age;
>       
>       private boolean authenticated;
>       
>       public String getName() {
>               return name;
>       }
>       
>       public void setName(String name) {
>               this.name = name;
>       }
>       
>       public int getAge() {
>               return age;
>       }
>       public void setAge(int age) {
>               this.age = age;
>       }
>       public boolean isAuthenticated() {
>               return authenticated;
>       }
>       
>       public void setAuthenticated(boolean authenticated) {
>               this.authenticated = authenticated;
>       }
>       
>       @Override
>       public String toString() {
>               return ToStringBuilder.reflectionToString(this);
>       }
> }
> {code}
> {code}
> java.lang.reflect.InvocationTargetException: Cannot set age
>       at 
> org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1017)
>       at 
> org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830)
>       at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433)
>       at 
> com.alibaba.apache.BeanUtils.BeanUtilsTest.testPopulate(BeanUtilsTest.java:32)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at junit.framework.TestCase.runTest(TestCase.java:168)
>       at junit.framework.TestCase.runBare(TestCase.java:134)
>       at junit.framework.TestResult$1.protect(TestResult.java:110)
>       at junit.framework.TestResult.runProtected(TestResult.java:128)
>       at junit.framework.TestResult.run(TestResult.java:113)
>       at junit.framework.TestCase.run(TestCase.java:124)
>       at junit.framework.TestSuite.runTest(TestSuite.java:232)
>       at junit.framework.TestSuite.run(TestSuite.java:227)
>       at 
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
>       at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
>       at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter 
> method in class 'class com.alibaba.apache.BeanUtils.TestBean'
>       at 
> org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2128)
>       at 
> org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948)
>       at 
> org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054)
>       at 
> org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015)
>       ... 22 more
> cn.edu.ccnu.ivan.apache.beanutils.testb...@17590db[name=<null>,age=0,authenticated=false]
> {code}

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

Reply via email to