maven 依赖辩论非常分析

[复制链接]
发表于 2025-9-18 05:35:22 | 显示全部楼层 |阅读模式
非常如下
  1. Description:
  2. An attempt was made to call a method that does not exist. The attempt was made from the following location:
  3.     com.google.common.cache.CacheBuilder.initialCapacity(CacheBuilder.java:353)
  4. The following method did not exist:
  5.     com.google.common.base.Preconditions.checkState(ZLjava/lang/String;I)V
  6. The calling method's class, com.google.common.cache.CacheBuilder, was loaded from the following location:
  7.     jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar!/com/google/common/cache/CacheBuilder.class
  8. The called method's class, com.google.common.base.Preconditions, is available from the following locations:
  9.     jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar!/com/google/common/base/Preconditions.class
  10.     jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar!/com/google/common/base/Preconditions.class
  11. The called method's class hierarchy was loaded from the following locations:
  12.     com.google.common.base.Preconditions: file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
  13. Action:
  14. Correct the classpath of your application so that it contains compatible versions of the classes com.google.common.cache.CacheBuilder and com.google.common.base.Preconditions
复制代码
非常栈分析
  1. com.google.common.cache.CacheBuilder.initialCapacity方法调用com.google.common.base.Preconditions.checkState
  2. com.google.common.cache.CacheBuilder.initialCapacity来自于/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar
  3. com.google.common.base.Preconditions.checkState方法来自于/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
  4. 分析过程
  5. 1、打印 classloader 发现类加载器一样
  6. 2、mvn:dependency 得到如下截图,由于 google-collections 比 guava 层级高,因此会加在google-collections jar 包中的Preconditions类
  7. 3、查看两个 jar 包中的字节码
  8. javap -v -classpath guava-30.1-jre.jar com.google.common.base.Preconditions | grep -A 10 "checkState"
  9. javap -v -classpath google-collections-1.0.jar com.google.common.base.Preconditions | grep -A 10 "checkState"
  10. 对比发现com.google.common.base.Preconditions类中的 checkState 方法没有com.google.common.base.Preconditions.checkState(ZLjava/lang/String;I)V
复制代码

办理办法:去除 google-collection 的依赖即可。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表