[ 
https://issues.apache.org/jira/browse/THRIFT-1226?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13057508#comment-13057508
 ] 

ojciec pijo edited comment on THRIFT-1226 at 6/29/11 10:13 PM:
---------------------------------------------------------------

I think there's no java serialization spec per se, but default mechanism always 
keeps references if particular instance is saved to the same stream more than 
once. it is mentioned here: 
http://java.sun.com/developer/technicalArticles/Programming/serialization/ 
("Caching Objects in the Stream").

For a testcase, I have generated the same pair of objects with Thrift 5 and 6. 
Test passes for Thrift5, fails for Thrift6:

[...]

@Test
public void testVersion5() throws Exception {
  A5 a = new A5();
  B5 b = new B5();
  //add the same instance twice
  b.addToItems(a);
  b.addToItems(a);
  
  B5 deserialized = (B5)serializeAndDeserialize(b);

  //with java serialization
  //we expect that references are preserved and [0] == [1]
  assertSame(deserialized.getItems().get(0), deserialized.getItems().get(1));
}


@Test
public void testVersion6() throws Exception {
  A6 a = new A6();
  B6 b = new B6();
  //add the same instance twice
  b.addToItems(a);
  b.addToItems(a);

  B6 deserialized = (B6)serializeAndDeserialize(b);

  //since Thrift6 overrides default java serialization by providing 
readObject/writeObject,
  //now it behaves in 'thrift' way - references are replaced by copies
  //and this assertion FAILS!
  assertSame(deserialized.getItems().get(0), deserialized.getItems().get(1));
}
  

      was (Author: ojciecpijo):
    I think there's no java serialization spec per se, but default mechanism 
always keeps references if particular instance is saved to the same stream more 
than once. it is mentioned here: 
http://java.sun.com/developer/technicalArticles/Programming/serialization/ 
("Caching Objects in the Stream").

For a testcase, I have generated the same pair of objects with Thrift 5 and 6. 
Test passes for Thrift5, fails for Thrift6:

[...]

  @Test
  public void testVersion5() throws Exception {
    A5 a = new A5();
    B5 b = new B5();
    //add the same instance twice
    b.addToItems(a);  
    b.addToItems(a);
    
    B5 deserialized = (B5)serializeAndDeserialize(b);
    
    //with java serialization
    //we expect that references are preserved and [0] == [1] 
    assertSame(deserialized.getItems().get(0), deserialized.getItems().get(1));
  }
 
  @Test
  public void testVersion6() throws Exception {
    A6 a = new A6();
    B6 b = new B6();
    //add the same instance twice
    b.addToItems(a);  
    b.addToItems(a);
    
    B6 deserialized = (B6)serializeAndDeserialize(b);
    
    //since Thrift6 overrides default java serialization by providing 
readObject/writeObject,
    //now it behaves in 'thrift' way - references are replaced by copies
    //and this assertion FAILS!
    assertSame(deserialized.getItems().get(0), deserialized.getItems().get(1));
  }
  
  
> command line option to disable overriding java serialization
> ------------------------------------------------------------
>
>                 Key: THRIFT-1226
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1226
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler
>    Affects Versions: 0.6, 0.6.1
>            Reporter: ojciec pijo
>         Attachments: testcase.zip
>
>
> bugfix THRIFT-1038 is a breaking change since it overrides default java 
> serialization mechanism. as a result, objects generated by Thrift v6 are not 
> compatible with java serialization rules (references between objects are lost 
> after deserialization). Please provide a command line parameter to disable 
> generating readObject/writeObject as a workaround.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to