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

Java generated deep copy is shallow

    XMLWordPrintableJSON

    Details

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

      Description

      Minimum reproducible scenario

      I have an IDL called test.thrift

      struct A {
        1: required B b;
      }
      
      struct B {
        1: required string id;
      }
      

      Then I generate java file

      thrift -gen java -out src/main/java/gen src/main/resources/test.thrift
      

      Generated object for A contains method called deepCopy, which is calling copy constructor, which is actually just shallow copy (copy references)

      class A {
      
      //...
      
      public A(A other) {
          if (other.isSetB()) {
            this.b = other.b;
          }
        }
      
        public A deepCopy() {
          return new A(this);
        }
      
      //...
      
      }
      

      Instead of copying references we need copy deepCopy recursively.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jking3 James E. King III
                Reporter:
                mishadoff Mykhailo Kozik
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: