java - java.lang.VerifyError 的 JUnit 错误:Jenkins 上的局部变量类型错误
问题描述
我正在用 maven 项目测试 Junit 的功能
这是我正在测试的功能
public boolean isJSONValid3(String jsonInString) {
final Gson gson = new Gson();
try {
gson.fromJson(jsonInString, Object.class);
return true;
} catch(JsonSyntaxException ex) {
return false;
}
}
以及 Jenkins 上的错误跟踪
junit.framework.AssertionFailedError: Exception in constructor: testIsJSONValid3 (java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
com/egroup/util/AttributeCheck.objectNotNull([Ljava/lang/Object;)Z @29: iload
Reason:
Type top (current frame, locals[5]) is not assignable to integer
Current Frame:
bci: @29
flags: { }
locals: { 'com/egroup/util/AttributeCheck', '[Ljava/lang/Object;', integer, integer }
stack: { }
Bytecode:
0x0000000: 033d 11ff ff3e 120b 1100 26b8 0011 2bbe
0x0000010: 3604 120b 1100 27b8 0011 0336 0515 0515
0x0000020: 0411 0027 3d11 0000 3ea2 0076 1c11 0027
0x0000030: a000 161d 1100 00a0 000f 120b 1c1d 04b8
0x0000040: 0031 11ff ff3e 120b 1100 28b8 0011 2b15
0x0000050: 0532 1100 283d 1100 003e c700 271c 1100
0x0000060: 28a0 0016 1d11 0000 a000 0f12 0b1c 1d04
0x0000070: b800 3111 ffff 3e12 0b11 0029 b800 1103
0x0000080: ac1d 9b00 0f12 0b1c 1d03 b800 3111 ffff
0x0000090: 3e12 0b11 0027 b800 1184 0501 a7ff 811d
0x00000a0: 9b00 0f12 0b1c 1d03 b800 3111 ffff 3e12
0x00000b0: 0b11 002c b800 1104 ac
Stackmap Table:
append_frame(@29,Integer,Integer)
same_frame_extended(@153)
chop_frame(@183,1)
at com.egroup.util.AttributeCheckTest.<init>(AttributeCheckTest.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at junit.framework.TestSuite.createTest(TestSuite.java:65)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:307)
at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
at junit.framework.TestSuite.<init>(TestSuite.java:129)
at com.egroup.util.AttributeCheckTest.suite(AttributeCheckTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.internal.runners.SuiteMethod.testFromSuiteMethod(SuiteMethod.java:35)
at org.junit.internal.runners.SuiteMethod.<init>(SuiteMethod.java:24)
at org.junit.internal.builders.SuiteMethodBuilder.runnerForClass(SuiteMethodBuilder.java:11)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
)
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
在eclipse ide上运行junit时可以工作,但是
错误时:
使用 Publish JUnit 报告和 Maven 安装在 Jenkins 上运行
jdk:java-1.8.0-openjdk-1.8.0.222-4
如何解决这个问题!?!?
这让我烦了几天!
解决方案
我修复了我的 pom.xml,在属性和插件中添加 -noverify 以通过字节码验证
<properties>
<argLine>-noverify</argLine>
</properties>
和插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version> <!-- or whatever current version -->
<configuration>
<source>1.8</source>
<target>1.8</target>
<argLine>-noverify</argLine>
</configuration>
</plugin>
它有效!顺便问一下,有没有更好的解决方案?
推荐阅读
- c++ - 如何知道 C2259 VS 2017 错误没有实现哪种方法?
- javascript - 将带有对象的数组转换为数组
- python - Boost Python Numpy - 未定义的初始化引用
- computer-vision - 从表面法线图像计算深度图像,对积分/求和算法感到困惑
- python - 在 npyscreen(Python 诅咒包装器)中应该如何调整小部件的大小?
- python - Python如何计算这个公式?
- api - 有没有办法使用 Office 365 管理活动 API 检索项目特定信息?
- javascript - 在 vanilla JS 中执行脚本期间更新 HTML 元素的内容
- python - 递归函数不返回任何东西,即使它看起来像是要返回
- http-headers - 如何更改无服务器框架中响应标头的状态码?