'Bad return type in ProtobufUtil.toScan(scan) using Java, spark and hbase

I have the following error "bad return type" when doing this assignment

ClientProtos.Scan proto = ProtobufUtil.toScan(scan);

I use these packages

  1. Scan hbase-client-2.4.11.jar
  2. ProtobufUtil hbase-client-2.4.11.jar
  3. ClientProtos hbase-protocol-2.4.11.jar
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.TableInputFormat;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.hadoop.hbase.util.Base64;

public class HBase_test {

    public static void main(String[] args) {
        SparkConf sparkConf = new SparkConf().setAppName("Testing").setMaster("local");
        JavaSparkContext sc = new JavaSparkContext(sparkConf);
        Configuration conf = HBaseConfiguration.create();
        Scan scan = new Scan();
        
        scan.addFamily("cf".getBytes());
        scan.addColumn("cf".getBytes(),"AMBIENTE".getBytes());
        
        try {
            ClientProtos.Scan proto = ProtobufUtil.toScan(scan);
            String scanToString = Base64.encodeBytes(proto.toByteArray());

            String tableName = "MONITOR:STATS";
            conf.set(TableInputFormat.INPUT_TABLE,tableName);
            conf.set(TableInputFormat.SCAN,scanToString);
        }
        catch (Exception e) {
            e.printStackTrace();
        } finally {
            
        }
        System.out.println(sc.appName());
    }
}
Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    org/apache/hadoop/hbase/protobuf/ProtobufUtil.toMutation(Lorg/apache/hadoop/hbase/protobuf/generated/ClientProtos$MutationProto;)Lorg/apache/hadoop/hbase/client/Mutation; @17: areturn
  Reason:
    Type 'org/apache/hadoop/hbase/client/Increment' (current frame, stack[0]) is not assignable to 'org/apache/hadoop/hbase/client/Mutation' (from method signature)
  Current Frame:
    bci: @17
    flags: { }
    locals: { 'org/apache/hadoop/hbase/protobuf/generated/ClientProtos$MutationProto', 'org/apache/hadoop/hbase/protobuf/generated/ClientProtos$MutationProto$MutationType' }
    stack: { 'org/apache/hadoop/hbase/client/Increment' }
  Bytecode:
    0x0000000: 2ab6 0081 4c2b b200 eda6 0009 2a01 b800
    0x0000010: f2b0 2bb2 00e5 a600 092a 01b8 00f3 b02b
    0x0000020: b200 caa6 0009 2a01 b800 c9b0 2bb2 0083
    0x0000030: a600 092a 01b8 0080 b0bb 0017 59bb 000a
    0x0000040: 59b7 000b 12f4 b600 0d2b b600 f5b6 0010
    0x0000050: b700 f6bf
  Stackmap Table:
    append_frame(@18,Object[#885])
    same_frame(@31)
    same_frame(@44)
    same_frame(@57)

        at hbase_test.HBase_test.main(HBase_test.java:25)

enter image description here

What am I doing wrong or do I have to update the package or do I need to add a package.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source