Commons Chain
  1. Commons Chain
  2. CHAIN-52

ContextBase subclasses, when cloned, end up with local property entries in the HashMap

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: Base
    • Labels:
      None
    • Environment:

      All OS's, JDK 6

      Description

      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.

        Activity

        Martin John Bartlett created issue -
        Hide
        Martin John Bartlett added a comment -

        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())
          Unknown macro: { Object key = keys.next(); if (descriptors.containsKey(key)) { copy.put(key, singleton); } }

          }
          copy.descriptors = savedDescriptors;
          return copy;
          }

        Show
        Martin John Bartlett added a comment - 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()) Unknown macro: { Object key = keys.next(); if (descriptors.containsKey(key)) { copy.put(key, singleton); } } } copy.descriptors = savedDescriptors; return copy; }
        Benedikt Ritter made changes -
        Field Original Value New Value
        Component/s Base [ 12320801 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Martin John Bartlett
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development