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)
      

            [CLOV-1779] Groovy code with Generics throw NPEs

            Owen made changes -
            Workflow Original: New Clover Workflow [ 931761 ] New: New Clover Workflow - Restricted [ 1475250 ]
            Marcus Silveira made changes -
            Regular Expression New: com.sun.beans.TypeResolver.resolve\(TypeResolver.java:\d+

            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!
            Grzegorz Lewandowski made changes -
            Resolution New: Fixed [ 1 ]
            Status Original: To be reviewed [ 10026 ] New: Closed [ 6 ]

            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
            Grzegorz Lewandowski made changes -
            Status Original: In Progress [ 3 ] New: To be reviewed [ 10026 ]
            Grzegorz Lewandowski made changes -
            Remote Link New: This issue links to "Clover › All JDK Tests › CLOV-1779_safe_eval_generic_method (devtools-bamboo)" [ 120545 ]
            Grzegorz Lewandowski made changes -
            Remote Link New: This issue links to "Clover › All Ant Groovy Tests › CLOV-1779_safe_eval_generic_method (devtools-bamboo)" [ 120544 ]
            Grzegorz Lewandowski made changes -
            Remote Link New: This issue links to "Clover › Default › CLOV-1779_safe_eval_generic_method (devtools-bamboo)" [ 120650 ]
            Grzegorz Lewandowski made changes -
            Assignee Original: Marek Parfianowicz [ mparfianowicz ] New: Grzegorz Lewandowski [ glewandowski ]

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

                Created:
                Updated:
                Resolved: