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

Enums generated for Java doesn't work for types in maps

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 0.9.1
    • None
    • Java - Compiler
    • None
    • Mac OSX

    Description

      I use the following thrift file to illustrate the bug:

      test.thrift
      enum TestEnum {
        ONE,
        TWO,
        THREE,
        FOUR,
      }
      
      const map<TestEnum,string> TestMap = {
        TestEnum.ONE: "one",
        TestEnum.TWO: "two",
        Testenum.THREE: "three",
        TestEnum.FOUR: "four",
      }
      

      I then run thift --gen java test.thrift and when I compile the classes I get the following errors:

      testConstants.java:37: illegal start of expression
          TestMap.put(.TestEnum.ONE, "one");
                      ^
      testConstants.java:37: ';' expected
          TestMap.put(.TestEnum.ONE, "one");
                       ^
      testConstants.java:37: illegal start of expression
          TestMap.put(.TestEnum.ONE, "one");
                               ^
      testConstants.java:37: <identifier> expected
          TestMap.put(.TestEnum.ONE, "one");
                                    ^
      testConstants.java:37: illegal start of expression
          TestMap.put(.TestEnum.ONE, "one");
                                          ^
      testConstants.java:38: illegal start of expression
          TestMap.put(.TestEnum.TWO, "two");
                      ^
      testConstants.java:38: ';' expected
          TestMap.put(.TestEnum.TWO, "two");
                       ^
      testConstants.java:38: illegal start of expression
          TestMap.put(.TestEnum.TWO, "two");
                               ^
      testConstants.java:38: <identifier> expected
          TestMap.put(.TestEnum.TWO, "two");
                                    ^
      testConstants.java:38: illegal start of expression
          TestMap.put(.TestEnum.TWO, "two");
                                          ^
      testConstants.java:39: illegal start of expression
          TestMap.put(.Testenum.THREE, "three");
                      ^
      testConstants.java:39: ';' expected
          TestMap.put(.Testenum.THREE, "three");
                       ^
      testConstants.java:39: illegal start of expression
          TestMap.put(.Testenum.THREE, "three");
                               ^
      testConstants.java:39: <identifier> expected
          TestMap.put(.Testenum.THREE, "three");
                                      ^
      testConstants.java:39: illegal start of expression
          TestMap.put(.Testenum.THREE, "three");
                                              ^
      testConstants.java:40: illegal start of expression
          TestMap.put(.TestEnum.FOUR, "four");
                      ^
      testConstants.java:40: ';' expected
          TestMap.put(.TestEnum.FOUR, "four");
                       ^
      testConstants.java:40: illegal start of expression
          TestMap.put(.TestEnum.FOUR, "four");
                               ^
      testConstants.java:40: <identifier> expected
          TestMap.put(.TestEnum.FOUR, "four");
                                     ^
      testConstants.java:40: illegal start of expression
          TestMap.put(.TestEnum.FOUR, "four");
                                            ^
      

      The offending piece of code is testConstants.java which looks like this:

      testConstants.java
      /**
       * Autogenerated by Thrift Compiler (0.9.1)
       *
       * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
       *  @generated
       */
      import org.apache.thrift.scheme.IScheme;
      import org.apache.thrift.scheme.SchemeFactory;
      import org.apache.thrift.scheme.StandardScheme;
      
      import org.apache.thrift.scheme.TupleScheme;
      import org.apache.thrift.protocol.TTupleProtocol;
      import org.apache.thrift.protocol.TProtocolException;
      import org.apache.thrift.EncodingUtils;
      import org.apache.thrift.TException;
      import org.apache.thrift.async.AsyncMethodCallback;
      import org.apache.thrift.server.AbstractNonblockingServer.*;
      import java.util.List;
      import java.util.ArrayList;
      import java.util.Map;
      import java.util.HashMap;
      import java.util.EnumMap;
      import java.util.Set;
      import java.util.HashSet;
      import java.util.EnumSet;
      import java.util.Collections;
      import java.util.BitSet;
      import java.nio.ByteBuffer;
      import java.util.Arrays;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      
      public class testConstants {
      
        public static final Map<TestEnum,String> TestMap = new HashMap<TestEnum,String>();
        static {
          TestMap.put(.TestEnum.ONE, "one");
          TestMap.put(.TestEnum.TWO, "two");
          TestMap.put(.Testenum.THREE, "three");
          TestMap.put(.TestEnum.FOUR, "four");
        }
      
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hsjunnesson Hans Sjunnesson
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: