You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Kevin Barrett (JIRA)" <ji...@apache.org> on 2009/05/06 19:05:30 UTC

[jira] Created: (THRIFT-489) Java enum validation only validates explicitly assigned values

Java enum validation only validates explicitly assigned values
--------------------------------------------------------------

                 Key: THRIFT-489
                 URL: https://issues.apache.org/jira/browse/THRIFT-489
             Project: Thrift
          Issue Type: Bug
          Components: Compiler (Java)
            Reporter: Kevin Barrett


Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:

{noformat}
enum testEnum {
    valueZero = 0,
    valueOne,
    valueTwo
}
{noformat}

generates the following code (excerpt):

{noformat}
public class testEnum {
  public static final int valueZero = 0;
  public static final int valueOne = 1;
  public static final int valueTwo = 2;

  public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
  public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
    put(valueZero, "valueZero");
    put(valueOne, "valueOne");
    put(valueTwo, "valueTwo");
  }};
}
{noformat}

If all enums are given explicit values, VALID_VALUES is initialized as follows:

{noformat}
  public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
{noformat}

If no explicit values are assigned, VALID_VALUES is initialized with no parameters.

Verified with r764072 and r771969.


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


[jira] Updated: (THRIFT-489) Java enum validation only validates explicitly assigned values

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

Kevin Barrett updated THRIFT-489:
---------------------------------

    Attachment:     (was: jvalidv.patch)

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>         Attachments: jvalidv_root.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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


[jira] Updated: (THRIFT-489) Java enum validation only validates explicitly assigned values

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

Kevin Barrett updated THRIFT-489:
---------------------------------

    Attachment: jvalidv.patch

This patch fixes VALID_VALUES generation to include all identifiers, and formats the output a little.

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>         Attachments: jvalidv.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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


[jira] Resolved: (THRIFT-489) Java enum validation only validates explicitly assigned values

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

Bryan Duxbury resolved THRIFT-489.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 0.2
         Assignee: Kevin Barrett

I just committed this patch (with slight spacing modifications to the first line). Thanks for the patch, Kevin!

Note, I am committing this patch to trunk, not the 0.1 branch. We can discuss if we should commit it to the branch, too.

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>            Assignee: Kevin Barrett
>             Fix For: 0.2
>
>         Attachments: jvalidv_root.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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


[jira] Commented: (THRIFT-489) Java enum validation only validates explicitly assigned values

Posted by "Kevin Barrett (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713851#action_12713851 ] 

Kevin Barrett commented on THRIFT-489:
--------------------------------------

The formatting is just for consistency, and without newlines you'd wind up with a pretty long line even with moderate-sized enums.  Didn't see a reason not to -- I'm not a Java developer so apologies if it introduces a performance hit of some kind.  The simplest thing would be to just take out the if ((*c_iter)->has_value()) test.

I'll resubmit the patch from the project root.

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>         Attachments: jvalidv.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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


[jira] Commented: (THRIFT-489) Java enum validation only validates explicitly assigned values

Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12713778#action_12713778 ] 

Bryan Duxbury commented on THRIFT-489:
--------------------------------------

This is a good change. I'm ok with spreading out the init over many lines, but is there some compelling reason to introduce a bunch of extra whitespace in the constructor call? Also, can you resubmit a patch that is taken relative to the root of the project instead of way down in the source tree? 

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>         Attachments: jvalidv.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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


[jira] Updated: (THRIFT-489) Java enum validation only validates explicitly assigned values

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

Kevin Barrett updated THRIFT-489:
---------------------------------

    Attachment: jvalidv_root.patch

Same diff taken from project root.

> Java enum validation only validates explicitly assigned values
> --------------------------------------------------------------
>
>                 Key: THRIFT-489
>                 URL: https://issues.apache.org/jira/browse/THRIFT-489
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java)
>            Reporter: Kevin Barrett
>         Attachments: jvalidv_root.patch
>
>
> Java client enum validation code is rejecting any value other than those explicitly assigned inside the enum declaration.  For example:
> {noformat}
> enum testEnum {
>     valueZero = 0,
>     valueOne,
>     valueTwo
> }
> {noformat}
> generates the following code (excerpt):
> {noformat}
> public class testEnum {
>   public static final int valueZero = 0;
>   public static final int valueOne = 1;
>   public static final int valueTwo = 2;
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero);
>   public static final Map<Integer, String> VALUES_TO_NAMES = new HashMap<Integer, String>() {{
>     put(valueZero, "valueZero");
>     put(valueOne, "valueOne");
>     put(valueTwo, "valueTwo");
>   }};
> }
> {noformat}
> If all enums are given explicit values, VALID_VALUES is initialized as follows:
> {noformat}
>   public static final IntRangeSet VALID_VALUES = new IntRangeSet(valueZero, valueOne, valueTwo);
> {noformat}
> If no explicit values are assigned, VALID_VALUES is initialized with no parameters.
> Verified with r764072 and r771969.

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