Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7518

hashCode() throws NPE when using @CompileStatic with @EqualsAndHashCode

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.4
    • Fix Version/s: 2.4.5
    • Component/s: None
    • Labels:
      None

      Description

      Given the following class

      Person.groovy
      import groovy.transform.CompileStatic
      import groovy.transform.EqualsAndHashCode
      
      @EqualsAndHashCode
      @CompileStatic
      class Person {
      	Long someLong
      }
      

      and the test

      PersonTest.groovy
      import static org.junit.Assert.*
      
      import org.junit.Test
      
      class PersonTest {
      
      	@Test
      	void hashcodeWithoutLongValue() {
      		def person = new Person()
      		assert person.hashCode()
      	}
      }
      

      and the gradle configuration:

      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'
      }
      

      when I run

      gradle clean build

      then the test fails with the following message.

      PersonTest > hashcodeWithoutLongValue FAILED
          java.lang.NullPointerException at PersonTest.groovy:10
      
      1 test completed, 1 failed
      :test FAILED
      

      With Groovy 2.4.3 the test passes.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              riggs Thomas
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: