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

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

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.


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

Posted by "Dave Engberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-651?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dave Engberg updated THRIFT-651:
--------------------------------

    Attachment: thrift-java-enum-const.patch

patch that replaces the numeric constant value with the symbolic name of the enumerated constant

> 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.


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

Posted by "Dave Engberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791092#action_12791092 ] 

Dave Engberg commented on THRIFT-651:
-------------------------------------


Oops, yeah, sorry.  I grabbed the 0.2 and assumed any compilation errors 
in the release would be new bugs, so didn't check for dups.  Your final 
patch fixes our compilation error.

Thanks




> 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.


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

Posted by "Dave Engberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/THRIFT-651?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dave Engberg resolved THRIFT-651.
---------------------------------

    Resolution: Duplicate

duplicate of THRIFT-632
https://issues.apache.org/jira/browse/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.


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

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ 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.