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

3

8

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?

Newman answered 2/9, 2014 at 10:38 Comment(0)
N
10

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:

Newman answered 2/9, 2014 at 10:38 Comment(2)
Arun is correct. This is a JDK bug so updating to at least 7u72 should solve it for you. I was experiencing the issue and after isntalling 7u72, my build works correctly.Maxiemaxilla
I can't vote up this solution enough. It was maddening since nobody else in my group had this problem (they had different 1.7 JDKs). Updating to u79 fixed me up.Peluso
S
5

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

Sitter answered 16/10, 2014 at 16:4 Comment(1)
I upgraded from jdk1.8.0_20.jdk to jdk1.8.0_191.jdk and it seems to have fixed the problem.Warila
G
4

It happens when Constructor calls super.

Adding @CompileStatic on Constructor solves the problem.

Gensler answered 16/9, 2014 at 20:3 Comment(1)
Simplest solution. Works great!Gamic

© 2022 - 2024 — McMap. All rights reserved.