[ 
https://issues.apache.org/jira/browse/THRIFT-2587?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nevo Hed updated THRIFT-2587:
-----------------------------

      Component/s:     (was: Java - Compiler)
                   Compiler (General)
      Description: 
The compiler seems to accept an incomplete symbol specification.  This may 
yield unusable code in some target languages.

Example yielding bad Java code:

{code:title=common.thrift|borderStyle=solid}
namespace java com.example.common

enum SomeEnum {
  SOMEENUM_X,
}
{code}


{code:title=myapi.thrift (incorrect enum reference)|borderStyle=solid}
include "common.thrift"

namespace java com.example.someapi

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

The correct reference would have been:
{code:title=myapi.thrift (correct enum reference)|borderStyle=solid}
include "common.thrift"

namespace java com.example.someapi

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

But the thrift compiler does not complain, and so the generated Java code  
contains "common" twice, with no type name.

{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}




  was:
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


    Fix Version/s:     (was: 0.9.2)
          Summary: Compiler should fully validate default values  (was: 
Compiled Java code doubles-up the namespace of default value)

> Compiler should fully validate default values
> ---------------------------------------------
>
>                 Key: THRIFT-2587
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2587
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (General)
>    Affects Versions: 0.9.1, 0.9.2
>            Reporter: Nevo Hed
>
> The compiler seems to accept an incomplete symbol specification.  This may 
> yield unusable code in some target languages.
> Example yielding bad Java code:
> {code:title=common.thrift|borderStyle=solid}
> namespace java com.example.common
> enum SomeEnum {
>   SOMEENUM_X,
> }
> {code}
> {code:title=myapi.thrift (incorrect enum reference)|borderStyle=solid}
> include "common.thrift"
> namespace java com.example.someapi
> struct MyStruct {
>   1: optional common.SomeEnum val=common.SOMEENUM_X
> }
> {code}
> The correct reference would have been:
> {code:title=myapi.thrift (correct enum reference)|borderStyle=solid}
> include "common.thrift"
> namespace java com.example.someapi
> struct MyStruct {
>   1: optional common.SomeEnum val=common.SomeEnum.SOMEENUM_X
> }
> {code}
> But the thrift compiler does not complain, and so the generated Java code  
> contains "common" twice, with no type name.
> {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}



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

Reply via email to