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 2002/11/12 14:30:13 UTC

DO NOT REPLY [Bug 14470] New: - Nested properties do not work for bean destination and mapped original

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=14470>.
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=14470

Nested properties do not work for bean destination and mapped original

           Summary: Nested properties do not work for bean destination and
                    mapped original
           Product: Commons
           Version: 1.0 Beta 1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Bean Utilities
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: praful.kapadia@ubsw.com


If dest is a bean and original data is a Map with indexed items, 
BeanUtils.copyProperties() throws 
exception "java.lang.IllegalArgumentException: Nested property names are not 
allowed".

An example entry for the the Map is myMap.put("list1[0].prop1", "new");

The code does most of the work but falls at the last hurdle!

The following code reproduces the bug on JDK1.3.1-b24:

//--------------------------------------------
package com.praful;

import java.util.*;
import org.apache.commons.beanutils.*;
import java.lang.reflect.*;
import org.apache.commons.logging.*;
import org.apache.commons.logging.impl.*;


public class BeanUtilTest2 {

    public static class ClassOne{
        public Vector getList1(){
            System.out.println("getList()");
            Vector result = new Vector();
            result.add(new ClassTwo());
            result.add(new ClassTwo());

            return result;
        }
        public void setList1(Vector l){
            System.out.println("setList()");
        }
    }

    public static class ClassTwo{
        public String getProp1(){
            System.out.println("getProp1()");
            return "prop1";
        }
        public void setProp1(String s){
            System.out.println("setProp1(): " + s);;
        }
    }

    public Map createData(){
        Map result = new HashMap();
        result.put("list1[0].prop1", "new");
        result.put("list1[1].prop1", "new2");
        //result.put("list1[1]", new ClassTwo());

        return result;
    }

    private void init(){
        //enabling full logging
        Log log = LogFactory.getLog(BeanUtils.class);
        if (log instanceof SimpleLog){
            SimpleLog sl = (SimpleLog)log;
            sl.setLevel(SimpleLog.LOG_LEVEL_ALL);
        }
    }

    public BeanUtilTest2() throws InvocationTargetException, 
IllegalAccessException {
        init();
        Map source = createData();
        Object dest = new ClassOne();
        BeanUtils.copyProperties(dest, source);
    }


    public static void main(String[] args) {

        try {
            BeanUtilTest2 beanUtilTest21 = new BeanUtilTest2();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>