groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7518) hashCode() throws NPE when using @CompileStatic with @EqualsAndHashCode
Date Thu, 23 Jul 2015 05:08:04 GMT

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

Paul King commented on GROOVY-7518:
-----------------------------------

I haven't checked 2.4.4 but in trunk we removed the use of the "dynamic" behavior of using
InvokerHelper.getProperty. So the AST transform used to produce this:
{code}
public int hashCode() {
     java.lang.Object _result = org.codehaus.groovy.util.HashCodeHelper.initHash()
    if (!(org.codehaus.groovy.runtime.InvokerHelper.getProperty(this, 'someLong').is(this)))
{
        _result = org.codehaus.groovy.util.HashCodeHelper.updateHash(_result, org.codehaus.groovy.runtime.InvokerHelper.getProperty(this,
'someLong'))
    }
    return _result 
}
{code}
but now produces this:
{code}
public int hashCode() {
    java.lang.Object _result = org.codehaus.groovy.util.HashCodeHelper.initHash()
    if (!(this.getSomeLong() == this )) {
          _result = org.codehaus.groovy.util.HashCodeHelper.updateHash(_result, this.getSomeLong())
    }
    return _result 
}

{code}

> hashCode() throws NPE when using @CompileStatic with @EqualsAndHashCode
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-7518
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7518
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.4
>            Reporter: Thomas
>
> Given the following class
> {code:title=Person.groovy}
> import groovy.transform.CompileStatic
> import groovy.transform.EqualsAndHashCode
> @EqualsAndHashCode
> @CompileStatic
> class Person {
> 	Long someLong
> }
> {code}
> and the test
> {code:title=PersonTest.groovy}
> import static org.junit.Assert.*
> import org.junit.Test
> class PersonTest {
> 	@Test
> 	void hashcodeWithoutLongValue() {
> 		def person = new Person()
> 		assert person.hashCode()
> 	}
> }
> {code}
> and the gradle configuration:
> {code:title=build.gradle}
> buildscript {
>     repositories {
>         mavenCentral()
>     }
> }
> apply plugin: 'groovy'
> apply plugin: 'eclipse'
> jar {
>     baseName = 'HashCodeNPE'
>     version = '0.0.1-SNAPSHOT'
> }
> sourceCompatibility = 1.8
> targetCompatibility = 1.8
> repositories {
>     mavenCentral()
> }
> dependencies {
>     compile("org.codehaus.groovy:groovy:2.4.4")
> 	testCompile("junit:junit:4.12")
> }
> eclipse {
>     classpath {
>          containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
>          containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
>     }
> }
> task wrapper(type: Wrapper) {
>     gradleVersion = '2.4'
> }
> {code}
> when I run {code}gradle clean build{code}
> then the test fails with the following message.
> {code}
> PersonTest > hashcodeWithoutLongValue FAILED
>     java.lang.NullPointerException at PersonTest.groovy:10
> 1 test completed, 1 failed
> :test FAILED
> {code}
> With Groovy 2.4.3 the test passes.



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

Mime
View raw message