[
https://issues.apache.org/jira/browse/THRIFT-4513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16393330#comment-16393330
]
ASF GitHub Bot commented on THRIFT-4513:
----------------------------------------
GitHub user romanoid opened a pull request:
https://github.com/apache/thrift/pull/1505
Fixing java thrift compiler to generate constants in stable order.
For description of the issue fixed, see:
https://issues.apache.org/jira/browse/THRIFT-4513
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/romanoid/thrift fix-constant-order
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/1505.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1505
----
commit 6a280b458f95a24d20bbc7798e145fe703ed23a0
Author: Roman Soroka <romanoid@...>
Date: 2018-03-08T23:45:22Z
Fixing java thrift compiler to generate constants in stable order.
See https://issues.apache.org/jira/browse/THRIFT-4513
----
> 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: Java - Compiler
> Reporter: Roman Soroka
> Priority: Major
>
> 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)