Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1779

Groovy code with Generics throw NPEs

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • 4.0.6
    • 4.0.1
    • Groovy
    • None

      Starting with Clover version 4.0.1 when running JUnit tests against clover instrumented code I am getting a null pointer exception when attempting to call this method:

      // in DateUtil.groovy
        static <T extends Date> T copy(T date) {
          (T) date?.clone()
        }
      

      It seems like something has changed with the instrumentation. Either of these two other variations of this same code doesn't have this problem:

        static Date copy(Date date) {
          date?.clone()
        }
      
        static def copy(def date) {
          date?.clone()
        }
      

      Here's the top of the stacktrace:

      java.lang.NullPointerException
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:203)
      	at com.sun.beans.TypeResolver.resolve(TypeResolver.java:218)
      	at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:96)
      	at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
      	at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116)
      	at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
      	at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
      	at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1205)
      	at java.beans.Introspector.getBeanInfo(Introspector.java:426)
      	at java.beans.Introspector.getBeanInfo(Introspector.java:173)
      	at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3244)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3242)
      	at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3225)
      	at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:222)
      	at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:253)
      	at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:255)
      	at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:859)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:72)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:159)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      	at com.surescripts.common.DateUtilTest.clone_NonNullValue(DateUtilTest.groovy:16)
      

          Form Name

            [CLOV-1779] Groovy code with Generics throw NPEs

            JoeA added a comment -

            Thanks a lot for fixing this. I think we will probably wait for the official release as this isn't really a blocker for us since 4.0.0 works well enough. Appreciate the work!

            JoeA added a comment - Thanks a lot for fixing this. I think we will probably wait for the official release as this isn't really a blocker for us since 4.0.0 works well enough. Appreciate the work!

            Thank you Joe for your help in resolving this issue. It occurred we had an bug in AST transformations which has been fixed. Fix will be included in upcoming 4.0.6 release but you can try SNAPSHOT version which is accessible in Atlassian Central Repository

            Grzegorz Lewandowski added a comment - Thank you Joe for your help in resolving this issue. It occurred we had an bug in AST transformations which has been fixed. Fix will be included in upcoming 4.0.6 release but you can try SNAPSHOT version which is accessible in Atlassian Central Repository

            JoeA added a comment -

            Marek, I tried using Groovy 2.4.4 today on our build and got the same results with Clover 4.0.5. Everything was successful with 2.4.4 and 4.0.0 though. Thanks for looking in to it. We are fine using Clover 4.0.0 for now, we just like to stay up to date on the tools we use as much as possible. Thanks!

            JoeA added a comment - Marek, I tried using Groovy 2.4.4 today on our build and got the same results with Clover 4.0.5. Everything was successful with 2.4.4 and 4.0.0 though. Thanks for looking in to it. We are fine using Clover 4.0.0 for now, we just like to stay up to date on the tools we use as much as possible. Thanks!

            Possibly related with CLOV-1490 implemented in 4.0.1.

            Marek Parfianowicz added a comment - Possibly related with CLOV-1490 implemented in 4.0.1.

            Marek Parfianowicz added a comment - Similar issues: https://issues.apache.org/jira/browse/GROOVY-7278 https://issues.apache.org/jira/browse/GROOVY-7298

            Hi Joe,

            I'd like to give you a status update. This bug has the highest priority and is included in our current sprint, so I hope to have a fix (and a snapshot build) mid of September the latest

            By the way: have you tried using the latest Groovy version - 2.4.4?

            unless it turns out to be a bug in groovyc which cannot be work-arounded on Clover side and developers of Groovy will have to make a fix.

            Cheers

            Marek Parfianowicz added a comment - Hi Joe, I'd like to give you a status update. This bug has the highest priority and is included in our current sprint, so I hope to have a fix (and a snapshot build) mid of September the latest By the way: have you tried using the latest Groovy version - 2.4.4? unless it turns out to be a bug in groovyc which cannot be work-arounded on Clover side and developers of Groovy will have to make a fix. Cheers

            JoeA added a comment -

            Thank you, let me know if you aren't able to reproduce the issue I can try distilling a smaller example in a full project.

            JoeA added a comment - Thank you, let me know if you aren't able to reproduce the issue I can try distilling a smaller example in a full project.

            Hi Joe, thank you very much for reporting this issue. We'll check what's wrong.

            Marek Parfianowicz added a comment - Hi Joe, thank you very much for reporting this issue. We'll check what's wrong.

              glewandowski Grzegorz Lewandowski
              a86e82895aec JoeA
              Affected customers:
              0 This affects my team
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: