user1686831
user1686831

Reputation: 13

Compilation errors on generated Java code Thrift 0.8.0

I was experimenting with a simple Thrift server and wanted to write the client in java. I ran the command

->thrift -gen java BLT.thrift

The generated java file Optimization.java shows the following error in the Eclipse IDE.

public static class Client extends org.apache.thrift.TServiceClient implements Iface

Error: The type TServiceClient cannot be the superclass of Client; asuperclass must be a class

public Client(org.apache.thrift.protocol.TProtocol prot)
{
  super(prot, prot);
}

The constructor Object(TProtocol, TProtocol) is undefined. .....

I still went ahead and compiled it.

->mvn clean install

Optimization.java:[38,54] no interface expected here
[ERROR] /thrift/Optimization.java:[39,83] type parameter model.thrift.Optimization.Client is not within its bound
[ERROR] /thrift/Optimization.java:[68,6] cannot find symbol
symbol  : method
sendBase(java.lang.String,com.model.thrift.Optimization.maximizeRevenue_args)
location: class model.thrift.Optimization.Client
[ERROR] /thrift/Optimization.java:[74,6] cannot find symbol
symbol  : method
receiveBase(model.thrift.Optimization.maximizeRevenue_result,java.lang.String)
location: class model.thrift.Optimization.Client
[ERROR] /thrift/Optimization.java:[98,97] cannot find symbol
symbol  : variable ___protocolFactory
location: model.thrift.Optimization.AsyncClient
[ERROR] /thrift/Optimization.java:[98,117] cannot find symbol
symbol  : variable ___transport
location: class model.thrift.Optimization.AsyncClient
[ERROR] /thrift/Optimization.java:[99,10] cannot find symbol
symbol  : variable ___currentMethod
location: class model.thrift.Optimization.AsyncClient
[ERROR] /thrift/Optimization.java:[100,6] cannot find symbol
symbol  : variable ___manager
location: class thrift.Optimization.AsyncClient
[ERROR] /thrift/Optimization.java:[387,23] cannot find symbol
symbol  : method getScheme()
location: class org.apache.thrift.protocol.TProtocol
[ERROR] /thrift/Optimization.java:[391,23] cannot find symbol
symbol  : method getScheme()
location: class org.apache.thrift.protocol.TProtocol
[ERROR] /thrift/Optimization.java:[665,23] cannot find symbol
symbol  : method getScheme()
location: class org.apache.thrift.protocol.TProtocol
[ERROR] /thrift/Optimization.java:[669,23] cannot find symbol
symbol  : method getScheme()

-> mvn dependency:tree | grep -i thrift
[INFO] \- org.apache.thrift:libthrift:jar:0.8.0:compile

-> thrift -version java
Thrift version 0.8.0

I did find this thread but the recommended solution didn't work for me Maven Thrift repository

I also did a checksum of the jar used for generating the code and the jar that got pulled using the above pom. Would anybody know why these would be different

->md5sum /usr/local/lib/libthrift-0.8.0.jar
fff7102558cb0ab1c103b62752166ce8  /usr/local/lib/libthrift-0.8.0.jar

->md5sum ~/.m2/repository/org/apache/thrift/libthrift/0.8.0/libthrift-0.8.0.jar
d68695bb2406cb2ab5fbae6ff6e27d7e
/home/nipun/.m2/repository/org/apache/thrift/libthrift/0.8.0/libthrift-0.8.0.jar

Any help/insight would be much appreciated.

Upvotes: 1

Views: 3758

Answers (1)

Wildfire
Wildfire

Reputation: 6418

Looks like you're linking with wrong libthrift version: org.apache.thrift.TServiceClient is defined as follows in 0.8.0:

public abstract class TServiceClient

and in 0.6.1:

public interface TServiceClient

I'd recommend to check if there are transitive dependencies in your project on old libthrift jar.

Upvotes: 1

Related Questions