groovy
  1. groovy
  2. GROOVY-5034

Groovy is producing incorrect generic type signatures for getters that are created by closures

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: None
    • Labels:
      None
    • Environment:
      OpenJDK (All Known Versions)
    • Number of attachments :
      0

      Description

      Example say you have a method like:

          def <T> T  mockController(Class<T> controllerClass) {
      
      
              doStuff {
                  println controllerClass
                  ....
              }
          }
      

      The closure passed to doStuff contains within its byte code a generated getter called "getControllerClass" with the following type signature:

        public Class<T> getControllerClass()
        {
          CallSite[] arrayOfCallSite = $getCallSiteArray();
          return (Class)ScriptBytecodeAdapter.castToType(this.controllerClass.get(), $get$$class$java$lang$Class());
          return null;
        }
      
      

      The generic type T is not declared anywhere. This causes exceptions on OpenJDK such as:

      java.lang.NullPointerException
      at com.sun.beans.TypeResolver.resolve(TypeResolver.java:321)
      at com.sun.beans.TypeResolver.resolve(TypeResolver.java:351)
      at com.sun.beans.TypeResolver.resolve(TypeResolver.java:310)
      at com.sun.beans.TypeResolver.resolve(TypeResolver.java:157)
      at com.sun.beans.TypeResolver.resolveInClass(TypeResolver.java:78)
      at java.beans.FeatureDescriptor.getReturnType(FeatureDescriptor.java:368)
      at java.beans.Introspector.getTargetEventInfo(Introspector.java:1020)
      at java.beans.Introspector.getBeanInfo(Introspector.java:424)
      at java.beans.Introspector.getBeanInfo(Introspector.java:189)
      at grails.test.mixin.web.ControllerUnitTestMixin.mockController(ControllerUnitTestMixin.groovy:268)
      
      

      This issue is the cause of http://jira.grails.org/browse/GRAILS-8031

        Activity

        Hide
        blackdrag blackdrag added a comment -

        should be fixed now

        Show
        blackdrag blackdrag added a comment - should be fixed now
        Hide
        Chris Love added a comment -

        I just opened http://jira.grails.org/browse/GRAILS-8184 are these related? If so what do I need to change in the groovy class that is attached to the bug?

        Show
        Chris Love added a comment - I just opened http://jira.grails.org/browse/GRAILS-8184 are these related? If so what do I need to change in the groovy class that is attached to the bug?
        Hide
        blackdrag blackdrag added a comment -

        Does it still happen if you remove the groovy transform?

        Show
        blackdrag blackdrag added a comment - Does it still happen if you remove the groovy transform?

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Graeme Rocher
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: