You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Bryan Duxbury (JIRA)" <ji...@apache.org> on 2009/12/16 00:21:18 UTC

[jira] Commented: (THRIFT-651) Java generator produces incorrect constant values

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

Bryan Duxbury commented on THRIFT-651:
--------------------------------------

Is this a duplicate of THRIFT-632? 

> Java generator produces incorrect constant values
> -------------------------------------------------
>
>                 Key: THRIFT-651
>                 URL: https://issues.apache.org/jira/browse/THRIFT-651
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>    Affects Versions: 0.2
>            Reporter: Dave Engberg
>         Attachments: thrift-java-enum-const.patch
>
>
> The Thrift Java code generator was modified at some point so that fields of type 'enum' were expressed using the name of the numeration instead of 'Integer'.
> This change broke constants of enum types, since the expressed constant initializer is still a numeric value rather than the named enumeration, which results in a Java compiler error.
> This TestEnum.thrift IDL:
>   enum TestEnum {
>         FIRST = 1,
>         SECOND = 2
>   }
>   const TestEnum TEST_CONST_VAL = FIRST;
>   const list<TestEnum> TEST_CONST_LIST = [ FIRST, SECOND ];
> ... produces this Constants.java that won't compile:
>   public class Constants {
>     public static final TestEnum TEST_CONST_VAL = 1;
>     public static final List<TestEnum> TEST_CONST_LIST = new ArrayList<TestEnum>();
>     static {
>       TEST_CONST_LIST.add(1);
>       TEST_CONST_LIST.add(2);
>     }
>   }
> The patch replaces these numeric initializers with symbolic enumerated values:
>   public class Constants {
>     public static final TestEnum TEST_CONST_VAL = TestEnum.FIRST;
>     public static final List<TestEnum> TEST_CONST_LIST = new ArrayList<TestEnum>();
>     static {
>       TEST_CONST_LIST.add(TestEnum.FIRST);
>       TEST_CONST_LIST.add(TestEnum.SECOND);
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.