Uploaded image for project: 'Railo'
  1. Railo
  2. RAILO-2042

Probable bug with duplicate()

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.3.4.003
    • Fix Version/s: 4.1.0.000, 4.0.1.001
    • Labels:
      None
    • Environment:

      Windows 7 various versions

    • Steps to Reproduce:
      Hide

      <cfscript>
      original = {
      innerStruct =

      { one = "Tahi" }

      };
      original.referenceToInnerStruct = original.innerStruct; // so those two references are pointing to the same struct in memory
      writeDump(var=original, label="Initial state of original");

      copiedByAssignment = original;
      writeDump(var=copiedByAssignment, label="Initial state of copiedByAssignment");
      writeOutput("<hr />");

      original.innerStruct.two = "Rua";
      writeDump(var=copiedByAssignment, label="copiedByAssignment after adding new key to innerStruct");
      writeDump(var=original, label="original after adding new key to innerStruct of copiedByAssignment");
      writeOutput("<hr />");

      duplicated = duplicate(original); // make a proper value-based copy; so completely different references pointing to different bits of memory
      writeDump(var=duplicated, label="Initial state of duplicated");
      writeOutput("<hr />");

      duplicated.innerStruct.three = "Toru";
      writeDump(var=duplicated, label="duplicated after adding new key to innerStruct");
      writeDump(var=original, label="original after adding new key to innerStruct of duplicated");
      writeDump(var=copiedByAssignment, label="copiedByAssignment after adding new key to innerStruct of duplicated");
      </cfscript>

      Show
      <cfscript> original = { innerStruct = { one = "Tahi" } }; original.referenceToInnerStruct = original.innerStruct; // so those two references are pointing to the same struct in memory writeDump(var=original, label="Initial state of original"); copiedByAssignment = original; writeDump(var=copiedByAssignment, label="Initial state of copiedByAssignment"); writeOutput("<hr />"); original.innerStruct.two = "Rua"; writeDump(var=copiedByAssignment, label="copiedByAssignment after adding new key to innerStruct"); writeDump(var=original, label="original after adding new key to innerStruct of copiedByAssignment"); writeOutput("<hr />"); duplicated = duplicate(original); // make a proper value-based copy; so completely different references pointing to different bits of memory writeDump(var=duplicated, label="Initial state of duplicated"); writeOutput("<hr />"); duplicated.innerStruct.three = "Toru"; writeDump(var=duplicated, label="duplicated after adding new key to innerStruct"); writeDump(var=original, label="original after adding new key to innerStruct of duplicated"); writeDump(var=copiedByAssignment, label="copiedByAssignment after adding new key to innerStruct of duplicated"); </cfscript>
    • Affects:
      Compatibility/Configuration

      Description

      (copied from https://groups.google.com/forum/?fromgroups=#!topic/railo/CLYPTWkCW3g)

      G'day
      I touched on this in a blog post I made last week: http://adamcameroncoldfusion.blogspot.co.uk/2012/08/complex-data-types-in-cf-and-how-theyre.html

      Consider the code attached

      What it does is demonstrate that struct references within a struct are not - I think - duplicated correctly in Railo (and OpenBD).

      I create a struct "original" which has a key "innerStruct" which itself is a struct. I make another reference to that original.innerStruct, original.referenceToInnerStruct. When this is duplicated in ColdFusion, the fact that innerStruct and referenceToInnerStruct are referencing the same actual struct in memory is maintained, whereas on Railo the connection is broken. Railo - it seems - is being too aggressive when it comes to duplicating things.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                micstriit Michael Offner
                Reporter:
                adamcameroncf Adam Cameron
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: