You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Nick Stokoe (JIRA)" <ji...@apache.org> on 2016/10/28 13:19:58 UTC

[jira] [Created] (GROOVY-7978) Code containing post-decrement in an assert can cause a VerifyError on instantiation

Nick Stokoe created GROOVY-7978:
-----------------------------------

             Summary: Code containing post-decrement in an assert can cause a VerifyError on instantiation
                 Key: GROOVY-7978
                 URL: https://issues.apache.org/jira/browse/GROOVY-7978
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.7, 2.4.5
         Environment: Ubuntu 14.04.5 LTS (Trusty)
Java: 1.8.0_91
x86_64 arch (both OS and Java)
            Reporter: Nick Stokoe


The program below attempts to show a minimal example. It fails with a VerifyError when an instance of class Bad is constructed. Removing the post-increment or the assert, or making it @CompileStatic makes the error go away.

{code}
// VerifyErrorExample.groovy
import groovy.transform.CompileStatic


class Bad {
	private int counter = 0;
	
	void bar() {
		assert (this.counter++) // Something about the post-decrement in an assert causes a VerifyError
	}
};

@CompileStatic
class Good {
	private int counter = 0;
	
	void bar() {
		assert (this.counter++) // This is fine
	}
};

println "Java: ${System.getProperty('java.version')}, Groovy: ${GroovySystem.version}"
new Good();
println "made a good"
new Bad();
println "made a bad"

{code}

The error looks like this:
{code}
 $ groovy VerifyErrorExample.groovy
Java: 1.8.0_91, Groovy: 2.4.7
made a good
Caught: java.lang.VerifyError: (class: Bad, method: bar signature: ()V) Expecting to find integer on stack
java.lang.VerifyError: (class: Bad, method: bar signature: ()V) Expecting to find integer on stack
	at VerifyErrorExample.run(VerifyErrorExample.groovy:24)
{code}

I've seen other errors of a similar sort, which I've not been able to boil down to a short example like this, but one I can remember seemed to be the result of code which use a void method in an if-condition (which the compiler didn't warn about), something like this:

{code}
  class Foo {
    public void voidMethod() {}
    public void bad() {
      if (voidMethod()) {
        prinln "hello"
      }
    }
  }

  new Foo(); // triggers the error
{code}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)