Gradle:坏< init>从分支内调用方法(invokespecial) [英] Gradle: Bad <init> method call from inside of a branch (invokespecial)
问题描述
当前版本的java(8u20,7u67)打破了gradle \groovy编译器和运行时兼容性:
:compileTestGroovy FAILED
失败:构建失败,出现异常。
*出错:
任务':compileTestGroovy'的执行失败。
>坏< init>方法调用
异常详细信息:
位置:
some / MyClass。< init>(Lsome / MyOtherClass;)V @ 71:invokespecial
原因:
字节码中存在错误
字节码:
0x0000000:b800 174d 04bd 0019 5903 2b53 5910 ff12
0x0000010:05b8 001f 2a5f ab00 0000 0055 0000 0003
0x0000020:f20b c677 0000 0022 0000 9b75 0000 0037
0x0000030:2cce be6d 0000 0040 5f5a 5903 3212 05b8
0x0000040:0023 c000 055f 57b7 0026 a700 2b5f 5a57
0x0000050:b700 29a7 0022 5f5a 5903 3212 2bb8 0023
0x0000060:c000 2b5f 57b7 002e a700 0dbb 0030 5912
0x0000070:32b7 0035 bf57 2ab6 0039 4e2d 2a5f b500
0x0000080:3b2d 572c 123c 322a 123e b900 4403 0057
0x0000090:b1
stackmap表:
full_frame(@ 56,{未初始化的,对象[#74],对象[#76]},{对象[#78],未初始化的})
full_f (@ 77,{UninitializedThis,Object [#74],Object [#76]},{Object [#78],Uninitialized}}
full_frame(@ 86,{UninitializedThis,Object [#74],Object [#76]},{Object [#78],UninitializedThis})
full_frame(@ 107,{未初始化的,对象[#74],对象[#76]},{对象[#78],未初始化的} )
full_frame(@ 117,{Object [#2],Object [#74],Object [#76]},{Object [#78]})
ZeroTurnaround的人也注意到了这种行为:
http://zeroturnaround.com/forums/topic/verifyerror-bad-method-call-from-inside-of-a-branch /
问题很简单:当我们在下一个版本的java中等待任何解决方案时,是否有解决此问题的方法?
处理VerifyError最明显的方法是使用-noverify jvm选项。
(假设gradle version> = 1.12,gradle wrapper为可执行文件)首先,告诉gradle使用编译过程的选项(在你的build.gradle中):
compileGroovy {
groovyOptions.forkOptions.jvmArgs = ['-noverify']
}
对于运行时,您还应该传递jvm选项:
测试任务:
测试{
jvmArgs'-noverify'
}
如果您使用应用程序插件:
applicationDefaultJvmArgs = [-noverify]
通过任何其他方式。
这就是全部。快乐的等待Java版本的修复:
Current versions of java (8u20, 7u67) break gradle\groovy compiler and runtime compatibility:
:compileTestGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestGroovy'.
> Bad <init> method call from inside of a branch
Exception Details:
Location:
some/MyClass.<init>(Lsome/MyOtherClass;)V @71: invokespecial
Reason:
Error exists in the bytecode
Bytecode:
0x0000000: b800 174d 04bd 0019 5903 2b53 5910 ff12
0x0000010: 05b8 001f 2a5f ab00 0000 0055 0000 0003
0x0000020: f20b c677 0000 0022 0000 9b75 0000 0037
0x0000030: 2cce be6d 0000 0040 5f5a 5903 3212 05b8
0x0000040: 0023 c000 055f 57b7 0026 a700 2b5f 5a57
0x0000050: b700 29a7 0022 5f5a 5903 3212 2bb8 0023
0x0000060: c000 2b5f 57b7 002e a700 0dbb 0030 5912
0x0000070: 32b7 0035 bf57 2ab6 0039 4e2d 2a5f b500
0x0000080: 3b2d 572c 123c 322a 123e b900 4403 0057
0x0000090: b1
Stackmap Table:
full_frame(@56,{UninitializedThis,Object[#74],Object[#76]},{Object[#78],UninitializedThis})
full_frame(@77,{UninitializedThis,Object[#74],Object[#76]},{Object[#78],UninitializedThis})
full_frame(@86,{UninitializedThis,Object[#74],Object[#76]},{Object[#78],UninitializedThis})
full_frame(@107,{UninitializedThis,Object[#74],Object[#76]},{Object[#78],UninitializedThis})
full_frame(@117,{Object[#2],Object[#74],Object[#76]},{Object[#78]})
People from ZeroTurnaround also noticed this behavior: http://zeroturnaround.com/forums/topic/verifyerror-bad-method-call-from-inside-of-a-branch/
The question is simple: while we wait for any solution in next versions of java, is there a workaround for this problem?
The most obvious way to deal with VerifyError is to use -noverify jvm option.
(Assuming gradle version >=1.12, and gradle wrapper as executable bin)
First of all, tell gradle to use the option for the compilation process (in your build.gradle):
compileGroovy {
groovyOptions.forkOptions.jvmArgs = ['-noverify']
}
For runtime, you should pass jvm option also:
Test task:
test {
jvmArgs '-noverify'
}
If you use application plugin:
applicationDefaultJvmArgs = ["-noverify"]
Or, by any other means.
That'll be all. Happy waiting for java release with fix:
这篇关于Gradle:坏< init>从分支内调用方法(invokespecial)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!