You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King, III (JIRA)" <ji...@apache.org> on 2018/03/14 17:12:01 UTC

[jira] [Resolved] (THRIFT-4513) thrift generated java code is not stable for constants

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

James E. King, III resolved THRIFT-4513.
----------------------------------------
       Resolution: Fixed
    Fix Version/s: 0.12.0

Committed - thanks!

> thrift generated java code is not stable for constants
> ------------------------------------------------------
>
>                 Key: THRIFT-4513
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4513
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Compiler (General)
>            Reporter: Roman Soroka
>            Assignee: James E. King, III
>            Priority: Major
>             Fix For: 0.12.0
>
>
> In certain cases, output generated with java compiler is unstable, this prevents correct incremental generation, artifact caching, etc. 
> This is especially crucible if the goal is reproducible builds: same results for the same source inputs. 
> Here's example: 
> Let's say we have thrift definition:
> const map<string, Enum1Enum2> CONSTANT_MAP =
> { 'key1' : \\{"enum1" : Enum1.ENUM1_VALUE1, "enum2" : Enum2.ENUM2_VALUE}
> ,
>  'key2' : \{"enum1" : Enum1.ENUM1_VALUE2, "enum2" : Enum2.ENUM2_VALUE},
>  'key3' : \{"enum1" : Enum1.ENUM1_VALUE3, "enum2" : Enum2.ENUM2_VALUE},
>  ....
>  }
> Compiler generates code like:
> public static final java.util.Map<java.lang.String,Enum1Enum2> CONSTANT_MAP = new java.util.HashMap<java.lang.String,Enum1Enum2>();
>  static {
>  Enum1Enum2 tmp199 = new Enum1Enum2();
>  tmp199.setEnum1(com.java.package.Enum1.ENUM1_VALUE2);
>  tmp199.setEnum2(com.java.package.Enum2.ENUM2_VALUE);
> CONSTANT_MAP.put("key2", tmp199);
>  Enum1Enum2 tmp200 = new Enum1Enum2();
>  tmp200.setEnum1(com.java.package.Enum1.ENUM1_VALUE1);
>  tmp200.setEnum2(com.java.package.Enum2.ENUM2_VALUE);
> CONSTANT_MAP.put("key1", tmp200);
>  Enum1Enum2 tmp201 = new Enum1Enum2();
>  tmp201.setEnum1(com.java.package.Enum1.ENUM1_VALUE3);
>  tmp201.setEnum2(com.java.package.Enum2.ENUM2_VALUE);
> CONSTANT_MAP.put("key3", tmp201);
> Possible reorderings:
> 1. Values are added in different order from run to run.
> 2. Set methods in value construction may be called in different order.
> Note: this results in equivalent java maps, so there is no runtime issues. 
> Proposed remedy: 
>  When building construction of Constants from JSON, java code generator should use by-key ordering.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)