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?

head_thrash
  • 1,623
  • 1
  • 21
  • 26

3 Answers3

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:

Lifeweaver
  • 986
  • 8
  • 29
head_thrash
  • 1,623
  • 1
  • 21
  • 26
  • 1
    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. – Mikezx6r Nov 25 '14 at 12:23
  • 1
    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. – Michael Oryl May 01 '15 at 15:03
5

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

Arun Gopalpuri
  • 2,340
  • 26
  • 27
4

It happens when Constructor calls super.

Adding @CompileStatic on Constructor solves the problem.

linuxeasy
  • 6,269
  • 7
  • 33
  • 40
Boaz Nahum
  • 1,049
  • 8
  • 9