You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2016/01/28 23:15:39 UTC

[jira] [Resolved] (THRIFT-3377) Deep copy is actually shallow when using typedef members

     [ https://issues.apache.org/jira/browse/THRIFT-3377?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jens Geyer resolved THRIFT-3377.
--------------------------------
       Resolution: Fixed
         Assignee: Roshan George
    Fix Version/s: 1.0

Committed - good catch, thank you! 


> Deep copy is actually shallow when using typedef members
> --------------------------------------------------------
>
>                 Key: THRIFT-3377
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3377
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.9.2
>            Reporter: Vincent Dumont
>            Assignee: Roshan George
>             Fix For: 1.0
>
>
> Consider the following structures:
> {code:title=thrift|borderStyle=solid}
> typedef set<i32> sset;
> struct Test {
>   1: set<i32> myset;
> }
> struct Test2 {
>   1: sset myset;
> }
> {code}
> 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. 
> {code:title=Test.java -- deep|borderStyle=solid}
>   /** 
>    * 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;
>     }   
>   }
> {code}
> VS
> {code:title=Test2.java -- shallow..?|borderStyle=solid}
>   /**
>    * Performs a deep copy on <i>other</i>.
>    */
>   public Test2(Test2 other) {
>     if (other.isSetMyset()) {
>       this.myset = other.myset;
>     }
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)