You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2021/03/30 23:09:00 UTC

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

    [ https://issues.apache.org/jira/browse/GROOVY-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17311851#comment-17311851 ] 

Paul King commented on GROOVY-7978:
-----------------------------------

[~emilles] Do we know fix version?

> 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.5, 2.4.7
>         Environment: Ubuntu 14.04.5 LTS (Trusty)
> Java: 1.8.0_91
> x86_64 arch (both OS and Java)
>            Reporter: Nick Stokoe
>            Assignee: Eric Milles
>            Priority: Major
>
> 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
(v8.3.4#803005)