Gradle: Bad <init> method call from inside of a branch (invokespecial)

只谈情不闲聊 提交于 2019-12-12 09:37:21

问题


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?


回答1:


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:

  • https://jira.codehaus.org/browse/GROOVY-6951
  • https://bugs.openjdk.java.net/browse/JDK-8051012



回答2:


This is a jdk bug & it has been fixed in latest jdk version 7 u72




回答3:


It happens when Constructor calls super.

Adding @CompileStatic on Constructor solves the problem.



来源:https://stackoverflow.com/questions/25621407/gradle-bad-init-method-call-from-inside-of-a-branch-invokespecial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!