All Products
Search
Document Center

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

Last Updated:Oct 24, 2024

If a PB library conflict occurs when you use Tablestore SDK for Java, you must make sure that the version of the tablestore library in the pom.xml file of the Maven project is the same as the version of the tablestore library in jar-with-dependencies, remove the protobuf-java and httpasyncclient dependencies from the tablestore library, and check whether library conflicts occur in the tablestore library.

Note

To check whether a PB or tablestore library conflict occurs, you can use mvn dependency:tree to print the dependency tree in your library and check whether protobuf-java, httpasyncclient, and the tablestore library have different versions of dependencies.

Problem description

The following exception occurs when I 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

protobuf-java V2.4.1 and httpasyncclient V4.0.2 on which Tablestore SDK for Java depends conflict with the same libraries in your applications. If the libraries on which your applications depend indirectly depend on the tablestore library, the version of the tablestore library conflicts with the version of the tablestore library on which your applications directly depend.

Solution

Add the following dependencies to the pom.xml file in the Maven project:

Note

The classifier is jar-with-dependencies, which packages protobuf-java and httpasyncclient by using rename package to remove the dependency on protobuf-java and httpasyncclient.

<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>tablestore</artifactId>
    <version>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>
    <!-- For example, the following libraries indirectly depend on Tablestore SDKs -->
    <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>