Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
0.9.1
-
None
-
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
- Is contained by
-
THRIFT-3089 Assigning default ENUM values results in non-compilable java code if java namespace is not defined
- Closed