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

Deep copy is actually shallow when using typedef members

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.2
    • 0.10.0
    • Java - Compiler
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: