Tablestore SDK for Java の使用時に PB ライブラリの競合が発生した場合は、Maven プロジェクトの pom.xml ファイル内の tablestore ライブラリのバージョンが jar-with-dependencies 内の tablestore ライブラリのバージョンと同じであることを確認し、tablestore ライブラリから protobuf-java および httpasyncclient の依存関係を削除し、tablestore ライブラリでライブラリの競合が発生していないか確認する必要があります。
PB または tablestore ライブラリの競合が発生しているかどうかを確認するには、mvn dependency:tree を使用してライブラリ内の依存関係ツリーを出力し、protobuf-java、httpasyncclient、および tablestore ライブラリに異なるバージョンの依存関係がないか確認します。
問題の説明
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) 原因
Tablestore SDK for Java が依存している protobuf-java V2.4.1 および httpasyncclient V4.0.2 は、アプリケーション内の同じライブラリと競合します。アプリケーションが依存しているライブラリが間接的に tablestore ライブラリに依存している場合、tablestore ライブラリのバージョンは、アプリケーションが直接依存している tablestore ライブラリのバージョンと競合する可能性があります。
解決策
Maven プロジェクトの pom.xml ファイルに次の依存関係を追加します。
classifier は jar-with-dependencies で、protobuf-java および httpasyncclient への依存関係を削除するために、名前変更パッケージを使用して protobuf-java および 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>
</dependency>
<dependency>
<!-- 例えば、以下のライブラリは間接的に Tablestore SDK に依存しています。 -->
<groupId>com.aliyun.xxxxxxx</groupId>
<artifactId>yyyyyy</artifactId>
<version>zzzzzzz</version>
<classifier>jar-with-dependencies</classifier>
<exclusions>
<!-- tablestore ライブラリへの間接的な依存関係を削除します。 -->
<exclusion>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
</exclusion>
</exclusions>
</dependency>