commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin John Bartlett (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CHAIN-52) ContextBase subclasses, when cloned, end up with local property entries in the HashMap
Date Mon, 20 Sep 2010 16:32:33 GMT

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

Martin John Bartlett updated CHAIN-52:
--------------------------------------


A functional, but probably not optimal, implementation of clone:


    /**
     * A shallow clone of the context is made, ensuring that only non-local properties remain
     * in the shallow clone of the Hashmap.
     */
    public Object clone() {
    	ContextBase copy = (ContextBase)super.clone();
    	Map savedDescriptors = copy.descriptors;
    	copy.descriptors = null;
        if (descriptors != null) {
            Iterator keys = copy.keySet().iterator();
            while (keys.hasNext()) {
                Object key = keys.next();
                if (descriptors.containsKey(key)) {
                	copy.put(key, singleton);
                }
            }
        }
        copy.descriptors = savedDescriptors;
    	return copy;
    }


> ContextBase subclasses, when cloned, end up with local property entries in the HashMap
> --------------------------------------------------------------------------------------
>
>                 Key: CHAIN-52
>                 URL: https://issues.apache.org/jira/browse/CHAIN-52
>             Project: Commons Chain
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: All OS's, JDK 6
>            Reporter: Martin John Bartlett
>
> When a context class is created based on ContextBase, an instance of that created, then
the local properties populated, then the instance cloned, each local property ends up in the
HashMap. As with other methods from HashMap overridden in ContextBase, clone should overridden
to prevent local properties being written to the HashMap.

-- 
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