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


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.

Reply via email to