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

        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.
        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.
        Hide
        Claude Brisson added a comment -

        commited

        Show
        Claude Brisson added a comment - commited

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development