You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Martin John Bartlett (JIRA)" <ji...@apache.org> on 2010/09/20 15:27:32 UTC

[jira] Created: (CHAIN-52) ContextBase subclasses, when cloned, end up with local property entries in the HashMap

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.


[jira] Updated: (CHAIN-52) ContextBase subclasses, when cloned, end up with local property entries in the HashMap

Posted by "Martin John Bartlett (JIRA)" <ji...@apache.org>.
     [ 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.