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

Nevo Hed commented on THRIFT-2587:
----------------------------------

This is probably a syntax error in my thrift file.
Adding the enum name in the default value makes the double "common" go away and 
replaced with a proper refrence

{code:title=myapi.thrift|borderStyle=solid}
include "common.thrift"

namespace java com.example.someapi

struct MyStruct {
  1: optional common.SomeEnum val=common.SomeEnum.SOMEENUM_X
}
{code}

This seems to be because the logic of 
[get_identifier_with_parent|https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=compiler/cpp/src/parse/t_const_value.h;h=ff422ae4690a4bdd5d1bac4dc4adf3b130c755ae;hb=HEAD#l148]
 which skips the first dot-separated keyword IFF at least 2 dots exist

Ideally the thrift compiler would alert on this, but that seems to be out of 
scope of this issue


> Compiled Java code doubles-up the namespace of default value
> ------------------------------------------------------------
>
>                 Key: THRIFT-2587
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2587
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.9.1, 0.9.2
>            Reporter: Nevo Hed
>             Fix For: 0.9.2
>
>
> This seems to happen when a struct with a field that has a default value,
> and said value is an enum defined in an included thrift file
> {code:title=common.thrift|borderStyle=solid}
> namespace java com.example.common
> enum SomeEnum {
>   SOMEENUM_X,
> }
> {code}
> {code:title=myapi.thrift|borderStyle=solid}
> include "common.thrift"
> namespace java com.example.someapi
> struct MyStruct {
>   1: optional common.SomeEnum val=common.SOMEENUM_X
> }
> {code}
> Compile:
> .../thrift --gen java myapi.thrift
> As you can see the namespace to the enum is wrong, as it contains "common" 
> twice.
> {code}
> $ grep SOMEENUM_ gen-java/com/example/someapi/MyStruct.java
>     this.val = com.example.common.common.SOMEENUM_X;
>     this.val = com.example.common.common.SOMEENUM_X;
> {code}
> Reproduced with latest upstream



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to