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

        Claude Brisson made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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 ]
        Jarkko Viinamäki made changes -
        Attachment velocity-712.patch [ 12441850 ]
        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