Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2435

Java compiler doesn't like struct member names that are identical to an existing enum or struct type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.9
    • 0.9.2
    • Java - Compiler
    • None

    Description

      The following IDL works fine in Python and C# but generates a compiler error in Java:

      namespace * test
      
      enum DataType {
          Text
      }
      
      struct Metadata {
          1: string Name,
          2: DataType DataType
      }
      
      service TestService {
          void SendData(1:string Data, 2:Metadata Metadata)
      }
      

      The generated test.Metadata.java file has 2 compile errors:

      Cannot make a static reference to the non-static field DataType

      at line 422:

      struct.DataType = DataType.findByValue(iprot.readI32());
      

      and line 495:

      struct.DataType = DataType.findByValue(iprot.readI32());
      

      If the IDL is changed to use DataType dataType instead then the compile errors don't occur.

      This issue is annoying because the same IDL works fine in Python and C#. To make the IDL work for Java we have to change the IDL, which means we have to change our Python clients (I haven't checked the C# clients yet). See also http://stackoverflow.com/questions/22691634/what-is-the-recommended-naming-convention-for-thrift-identifiers-in-order-to-max

      Attachments

        1. DataType.java
          0.8 kB
          Lucas Partridge
        2. Metadata.java
          15 kB
          Lucas Partridge
        3. test.thrift
          0.2 kB
          Lucas Partridge
        4. TestService.java
          30 kB
          Lucas Partridge
        5. THRIFT-2435_java_enum_type__conflicts_with_struct_member.patch
          2 kB
          Jens Geyer

        Activity

          People

            jensg Jens Geyer
            trillian Lucas Partridge
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: