You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/02/13 17:46:45 UTC

DO NOT REPLY [Bug 26918] New: - Cannot populate Stirng[][] properties with beanutils

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26918>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26918

Cannot populate Stirng[][] properties with beanutils

           Summary: Cannot populate Stirng[][] properties with beanutils
           Product: Commons
           Version: 1.6 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Bean Utilities
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: Ludovic.Maitre@fr.oleane.com


Hello,

It seems that BeanUtils.populate(bean,map) cannot populate properties whose type
is "double" (or triple, or quadruple...) arrays. 

The following testCase seems to prove this :

/////////////////////////////////////////////////

package fr.factory.test.commons;

import java.util.HashMap;

import junit.framework.TestCase;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Class TestBeanUtils
 * @author lmaitre
 */
public class TestBeanUtils extends TestCase {
	
	private Log log = LogFactory.getLog(TestBeanUtils.class);
	
	/**
	 * Constructor for TestBeanUtils.
	 * @param name
	 */
	public TestBeanUtils(String name) {
		super(name);
	}
	public static void main(String[] args) {
		junit.textui.TestRunner.run(TestBeanUtils.class);
	}
	
	final public void testPopulate() {
		SampleBean bean = new SampleBean();
		String[][] sampleValue = {
			{ "toto","titi"
			},
			{ "tata","tutu"
			}
		};
		HashMap properties = new HashMap();
		properties.put("doubleArrayProperty",sampleValue);
		try {
			BeanUtils.populate(bean,properties);
			assertTrue(bean.getDoubleArrayProperty()==sampleValue);
		} catch (Exception e) {
			log.debug("Exception :" + e.getMessage());
			e.printStackTrace();
		}		
	}
	
	private class SampleBean {
		
		private String[][] doubleArrayProperty;				
		
		/**
		 * Method getDoubleArrayProperty
		 * @return String[][]
		 */
		public String[][] getDoubleArrayProperty() {
			return doubleArrayProperty;
		}

		/**
		 * Method setDoubleArrayProperty
		 * @return void
		 */
		public void setDoubleArrayProperty(String[][] strings) {
			doubleArrayProperty= strings;
		}

	}
}

//////////////////////////////////////////////////////////////

this give the following stack trace :
java.lang.reflect.InvocationTargetException: Cannot set doubleArrayProperty
	at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1022)
	at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
	at fr.factory.test.commons.TestBeanUtils.testPopulate(TestBeanUtils.java:47)
	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:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)17:40:16
TestBeanUtils: Exception :Cannot set doubleArrayProperty

	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Caused by: java.lang.NoSuchMethodException: Property 'doubleArrayProperty' has
no setter method
	at
org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1782)
	at
org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
	at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
	at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
	... 17 more

So, i have tested this with BeanUtils 1.6.1 (but perhaps i have forgotten an
obvious thing ?).

I precise that i must absolutely use this type of functionnality (in struts)
so... i will pass my week end to patch this. I hope that i will give a patch monday.

If somebody find a workaround before monday i really appreciate if he can cc me
the solution to my personal mailbox at ludovic.maitre@free.fr

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org