flow-core-x icon indicating copy to clipboard operation
flow-core-x copied to clipboard

“NoSuchMethodErrors” due to multiple versions of com.google.guava:guava:jar

Open Bing-ok opened this issue 3 years ago • 1 comments

Issue description:

Hi, there are multiple versions of com.google.guava:guava in flow-core-x\zookeeper. As shown in the following dependency tree, according to Maven's "nearest wins" strategy, only com.google.guava:guava:21.0 can be loaded, com.google.guava:guava:27.0.1-jre will be shadowed.

However, several methods defined in shadowed version com.google.guava:guava:27.0.1-jre are referenced by client project via org.apache.curator:curator-recipes:4.3.0 but missing in the actually loaded version com.google.guava:guava:21.0.

For instance, the following missing method(defined in com.google.guava:guava:27.0.1-jre) are actually referenced by flow-core-x\zookeeper, which will introduce a runtime error(i.e., "NoSuchMethodError") into flow-core-x\zookeeper.

com.google.common.reflect.TypeToken: java.lang.reflect.Type access$500(com.google.common.reflect.TypeToken) is invoked by flow-core-x\zookeeper via the following path:


Invocation path------
<com.flowci.zookeeper.ZookeeperClient: void lock(java.lang.String,java.util.function.Consumer)> flow-core-x\zookeeper\target\classes
<org.apache.curator.shaded.com.google.common.collect.Multimaps$add__391: void accept(java.lang.Object)> flow-core-x\zookeeper\target\classes
<com.google.common.collect.Collections2$FilteredCollection: boolean add(java.lang.Object)> Repositories\com\google\guava\guava\27.0.1-jre\guava-27.0.1-jre.jar
<org.apache.curator.shaded.com.google.common.reflect.TypeToken$TypeFilter$1: boolean apply(java.lang.Object)> Repositories\org\apache\curator\curator-client\4.3.0\curator-client-4.3.0.jar
<org.apache.curator.shaded.com.google.common.reflect.TypeToken$TypeFilter$1: boolean apply(com.google.common.reflect.TypeToken)> Repositories\org\apache\curator\curator-client\4.3.0\curator-client-4.3.0.jar
<com.google.common.reflect.TypeToken: java.lang.reflect.Type access$500(com.google.common.reflect.TypeToken)>

Suggested fixing solutions:

  1. Declare a direct dependency com.google.guava:guava:27.0.1-jre in the pom file of flow-core-x\zookeeper. Because version 27.0.1-jre includes the above missing methods and is compatible with other versions of com.google.guava:guava in the project. This repair will introduce the following new dependencies: com.google.guava:failureaccess:1.0.1 com.google.errorprone:error_prone_annotations:2.2.0 com.google.j2objc:j2objc-annotations:1.1 org.checkerframework:checker-qual:2.5.2 com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava org.codehaus.mojo:animal-sniffer-annotations:1.17 com.google.code.findbugs:jsr305:3.0.2

  2. Upgrade dependency org.apache.curator:curator-recipes from 4.3.0 to 5.0.0.Because the newer version org.apache.curator:curator-recipes:5.0.0 introduces com.google.guava:guava:27.0.1-jre, such changing can solve the problem. This repair will introduce the following new dependencies: commons-lang:commons-lang:2.6

Please let me know which solution do you prefer? I can submit a PR to fix it.

Thank you very much for your attention. Best regards,

Dependency tree----


com.flowci:zookeeper:jar:1.0-SNAPSHOT
+- org.apache.curator:curator-recipes:jar:4.3.0:compile
|  \- org.apache.curator:curator-framework:jar:4.3.0:compile
|     \- org.apache.curator:curator-client:jar:4.3.0:compile
|        +- org.apache.zookeeper:zookeeper:jar:3.5.7:compile
|        |  +- org.apache.zookeeper:zookeeper-jute:jar:3.5.7:compile
|        |  |  \- (org.apache.yetus:audience-annotations:jar:0.5.0:compile - omitted for duplicate)
|        |  +- org.apache.yetus:audience-annotations:jar:0.5.0:compile
|        |  +- io.netty:netty-handler:jar:4.1.39.Final:compile (version managed from 4.1.45.Final)
|        |  |  +- io.netty:netty-common:jar:4.1.39.Final:compile
|        |  |  +- io.netty:netty-buffer:jar:4.1.39.Final:compile
|        |  |  |  \- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  +- io.netty:netty-transport:jar:4.1.39.Final:compile
|        |  |  |  +- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  |  +- (io.netty:netty-buffer:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  |  \- io.netty:netty-resolver:jar:4.1.39.Final:compile
|        |  |  |     \- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  \- io.netty:netty-codec:jar:4.1.39.Final:compile
|        |  |     +- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |     +- (io.netty:netty-buffer:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |     \- (io.netty:netty-transport:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  +- io.netty:netty-transport-native-epoll:jar:4.1.39.Final:compile (version managed from 4.1.45.Final)
|        |  |  +- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  +- (io.netty:netty-buffer:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  +- (io.netty:netty-transport:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |  \- io.netty:netty-transport-native-unix-common:jar:4.1.39.Final:compile
|        |  |     +- (io.netty:netty-common:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |     +- (io.netty:netty-buffer:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  |     \- (io.netty:netty-transport:jar:4.1.39.Final:compile - omitted for duplicate)
|        |  +- (org.slf4j:slf4j-api:jar:1.7.28:compile - version managed from 1.7.25; omitted for duplicate)
|        |  \- log4j:log4j:jar:1.2.17:compile
|        +- (com.google.guava:guava:jar:27.0.1-jre:compile - omitted for conflict with 21.0)
|        \- org.slf4j:slf4j-api:jar:1.7.28:compile
+- org.projectlombok:lombok:jar:1.18.0:provided
+- com.google.guava:guava:jar:21.0:compile
\- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
   \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile

Bing-ok avatar Jan 27 '21 09:01 Bing-ok

Could you help me review this issue? 👍 Thanks! @gy2006

Bing-ok avatar Jan 27 '21 09:01 Bing-ok