Velocity
  1. Velocity
  2. VELOCITY-712

Velocity Context clone() method doesn't do a deep cloning as mentioned in the javadoc

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      None

      Description

      Looking at the code it does:

          public Object clone()
          {
              VelocityContext clone = null;
              try
              {
                  clone = (VelocityContext) super.clone();
                  clone.context = new HashMap(context);
              }
              catch (CloneNotSupportedException ignored)
              {
              }
              return clone;
          }
      

      new HashMap() will not perform deep cloning but only shallow cloning.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        1141d 1h 29m 1 Claude Brisson 25/Apr/12 12:32
        Claude Brisson made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Claude Brisson added a comment -

        commited

        Show
        Claude Brisson added a comment - commited
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551689 ] jira [ 12552561 ]
        Mark Thomas made changes -
        Workflow jira [ 12454448 ] Default workflow, editable Closed status [ 12551689 ]
        Hide
        Misagh Moayyed added a comment -

        I am working on the deep clone issue here. I think one strategy here would be to serialize the context and then deserialize it, although the issue here is, items need to implement serializable. Otherwise, I think the context recursively needs to clone itself and the items inside.

        Show
        Misagh Moayyed added a comment - I am working on the deep clone issue here. I think one strategy here would be to serialize the context and then deserialize it, although the issue here is, items need to implement serializable. Otherwise, I think the context recursively needs to clone itself and the items inside.
        Jarkko Viinamäki made changes -
        Attachment velocity-712.patch [ 12441850 ]
        Hide
        Jarkko Viinamäki added a comment -

        This patch just fixes the JavaDoc and doesn't change the code in any way.

        Show
        Jarkko Viinamäki added a comment - This patch just fixes the JavaDoc and doesn't change the code in any way.
        Vincent Massol made changes -
        Description Looking at the code it does:

        {noformat}
            public Object clone()
            {
                VelocityContext clone = null;
                try
                {
                    clone = (VelocityContext) super.clone();
                    clone.context = new HashMap(context);
                }
                catch (CloneNotSupportedException ignored)
                {
                }
                return clone;
            }
        {noformat}

        newHashMap() will not perform deep cloning but only shallow cloning.
        Looking at the code it does:

        {noformat}
            public Object clone()
            {
                VelocityContext clone = null;
                try
                {
                    clone = (VelocityContext) super.clone();
                    clone.context = new HashMap(context);
                }
                catch (CloneNotSupportedException ignored)
                {
                }
                return clone;
            }
        {noformat}

        new HashMap() will not perform deep cloning but only shallow cloning.
        Vincent Massol made changes -
        Summary Velocity Context clone() method doesn't do a deep cloning as mentioned Velocity Context clone() method doesn't do a deep cloning as mentioned in the javadoc
        Vincent Massol made changes -
        Field Original Value New Value
        Description Looking at the code it does:

        {noformat}
            public Object clone()
            {
                VelocityContext clone = null;
                try
                {
                    clone = (VelocityContext) super.clone();
                    clone.context = new HashMap(context);
                }
                catch (CloneNotSupportedException ignored)
                {
                }
                return clone;
            }
        noformat}

        newHashMap() will not perform deep cloning but only shallow cloning.
        Looking at the code it does:

        {noformat}
            public Object clone()
            {
                VelocityContext clone = null;
                try
                {
                    clone = (VelocityContext) super.clone();
                    clone.context = new HashMap(context);
                }
                catch (CloneNotSupportedException ignored)
                {
                }
                return clone;
            }
        {noformat}

        newHashMap() will not perform deep cloning but only shallow cloning.
        Vincent Massol created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Vincent Massol
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development