What do I do if PB library conflicts occur when I use Tablestore SDK for Java?

Updated at:

If PB library conflicts occur when you use Tablestore SDK for Java, use the jar-with-dependencies version of the tablestore artifact in the pom.xml file of your Maven project. Remove the dependencies on protobuf-java and httpasyncclient from the tablestore artifact, and check whether the tablestore artifact itself has library conflicts.

Note

How do I initially check whether there are PB library or tablestore artifact conflicts?

In your repository, run mvn dependency:tree to print the dependency tree, and then check the tree for different versions of the protobuf-java, httpasyncclient, and tablestore dependencies.

Problem description

The following exception occurs when you use Tablestore SDK for Java:

Caused by: java.lang.UnsupportedOperationException: This is supposed to be overridden by subclassed
        at com.google.protobuf.GeneratedMessage.getUnknownFields(GeneratedMessage.java:225) 

Cause

Tablestore SDK for Java depends on version 2.4.1 of protobuf-java and version 4.0.2 of httpasyncclient, which can conflict with the same libraries bundled in your application. In addition, if another library that you depend on indirectly depends on the tablestore artifact, it can conflict with the tablestore artifact that your application directly depends on.

Solution

Add the following dependencies to the pom.xml file of your Maven project.

Note

The jar-with-dependencies classifier packages the protobuf-java and httpasyncclient dependencies by renaming their packages, which removes the dependencies on protobuf-java and httpasyncclient.

<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>tablestore</artifactId>
    <version>Replace with your current version</version>
    <classifier>jar-with-dependencies</classifier>
    <exclusions>
        <exclusion>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <!-- The following library is assumed to indirectly depend on Tablestore SDK -->
    <groupId>com.aliyun.xxxxxxx</groupId>
    <artifactId>yyyyyy</artifactId>
    <version>zzzzzzz</version>
    <classifier>jar-with-dependencies</classifier>
    <exclusions>
        <!-- Remove the indirect dependency on the tablestore library -->
        <exclusion>
            <groupId>com.aliyun.openservices</groupId>
            <artifactId>tablestore</artifactId>
        </exclusion>
    </exclusions>
</dependency>