在Java 8中运行PowerMock时如何修复VerifyError [英] How do I fix VerifyError when running PowerMock in Java 8

查看:1080
本文介绍了在Java 8中运行PowerMock时如何修复VerifyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的单元测试中使用 PowerMockerRule ,这样我可以在使用Spring的JUnit Runner运行它们时使用PowerMockito。但是,当我将规则添加到测试中时,我得到 java.lang.VerifyError

I want to use PowerMockerRule in my unit tests so that I can use PowerMockito in them while I run them with Spring's JUnit Runner. However, when I add the rule to my test, I get java.lang.VerifyError.

java.lang.VerifyError: Expecting a stackmap frame at branch target 47
Exception Details:
  Location:
    com/sample/package/MyClass.<init>(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V @25: if_icmpge
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: 2a2b 2c01 c000 32b7 0050 2d3a 0419 04be
    0x0000010: 3605 0336 0615 0615 05a2 0016 1904 1506
    0x0000020: 323a 072a 1907 b600 4984 0601 a7ff e9b1
    0x0000030:

到目前为止,我所做的一直是将我的javassist依赖项更新为3.20。 0-GA根据我的初始搜索,通常是问题。但是,它仍然无法解决我的问题。还有其他想法吗?

What I've done so far has been to update my javassist dependency to 3.20.0-GA as according to my initial searches, it's usually the problem. However, it still doesn't resolve the issues for me. Any other ideas?

推荐答案

首先是关于问题的根本原因。
JVM验证用户类以确保该类是安全的并且它不会违反某些规则。
现在在热点中有2个验证器:ClassVerifier(SplitVerifier)和旧验证器。在java 6中添加了新的验证器(SplitVerifier),它是可选的。这个新的验证器在类文件(StackMapTable属性)中需要更多信息。这个属性由编译器添加,它跟踪局部变量的类型。

First about root cause of your problem. JVM verifies user classes to ensure that class is "safe" and that it will not violate some rules. Now in hotspot there are 2 verifiers: ClassVerifier (SplitVerifier) and old verifier. New verifier (SplitVerifier) was added in java 6 and was optional. This new verifier needs some more information in class file (StackMapTable attribute). This attribute is added by compiler and it tracks types of local variables.

问题是一些检测库可以修改你的代码并且不更新StackMapTable(因为bug或者库是旧的,不知道这个属性)

Problem is that some instrumentation libraries can modify your code and don't update StackMapTable ( because of bugs or libraries are old and don't know about this attribute)

如何解决(选择一个):


  1. 禁用验证 -Xverify:none

  2. 更新\选择其他工具库

  3. 排除已修改的类

  4. 将类主要版本降级为50(java 6)及以下(在此情况下将使用旧验证程序)

  1. Disable verification -Xverify:none
  2. Update\choose another instrumentation library
  3. Exclude class from been modified
  4. Downgrade class major version to 50 (java 6) and below (in this case old verifier will be used)

这篇关于在Java 8中运行PowerMock时如何修复VerifyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆