Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3377

Deep copy is actually shallow when using typedef members

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.2
    • Fix Version/s: 0.10.0
    • Component/s: Java - Compiler
    • Labels:
      None

      Description

      Consider the following structures:

      thrift
      typedef set<i32> sset;
      
      struct Test {
        1: set<i32> myset;
      }
      
      struct Test2 {
        1: sset myset;
      }
      

      The generated code for Test's copy constructor looks fine, it deep copies the set. However, Test2, which should be equivalent, actually does not deep-copy the set and instead simply does a shallow assignment like if it was a POD type.

      Test.java – deep
        /** 
         * Performs a deep copy on <i>other</i>.
         */
        public Test(Test other) {
          if (other.isSetMyset()) {
            Set<Integer> __this__myset = new HashSet<Integer>(other.myset);
            this.myset = __this__myset;
          }   
        }
      

      VS

      Test2.java – shallow..?
        /**
         * Performs a deep copy on <i>other</i>.
         */
        public Test2(Test2 other) {
          if (other.isSetMyset()) {
            this.myset = other.myset;
          }
        }
      

        Attachments

          Activity

            People

            • Assignee:
              roshangeorge Roshan George
              Reporter:
              vdumont Vincent Dumont
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: