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

NPE on TypeResolver using anonymous inner class and the jdk7 compiler

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.1
    • 2.4.0-rc-1
    • Compiler
    • None
    • Groovy Version: 2.2.1 JVM: 1.7.0_51 Vendor: Oracle Corporation OS: Linux

    Description

      I systematically obtain a NullPointerException running some code compiled with the jdk1.7.0_51 (Oracle).

      Here is an excerpt from the minimal project I've attached at project.zip

      AbstractFoo.groovy
      package acme
      
      abstract class AbstractFoo<T,M> implements Foo<T,M> {
          public Foo<T,M> bind (Bar bar, Closure c) {
              bind (bar, new Foo<T,M>() {
                      T foo(Bar innerBar, M model) {
                          c.call (innerBar)
                      }
              })//FAILS
      		
      //		bind (bar, [doIt: {}] as Foo) //WORKS
          }
          public abstract AbstractFoo<T,M> bind (Bar bar, Foo<T,M> delegate)
      }
      
      Additional info
      1. Replacing the anonymous inner class with a map-based interface implementation it works.
      2. Using the jdk6 to compile and run the code it works.
      3. Compiling the code from Eclipse (using its compiler) then it works.

      This is the error 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:114)
      at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
      at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
      at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1149)
      at java.beans.Introspector.getBeanInfo(Introspector.java:416)
      at java.beans.Introspector.getBeanInfo(Introspector.java:163)
      at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3065)
      at java.security.AccessController.doPrivileged(Native Method)
      at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3063)
      at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3046)
      at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:176)
      at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:192)
      at acme.AbstractFoo$1.$getStaticMetaClass(AbstractFoo.groovy)
      at acme.AbstractFoo$1.<init>(AbstractFoo.groovy)
      at acme.AbstractFoo.bind(AbstractFoo.groovy:5)
      at acme.AbstractFoo$bind.call(Unknown Source)
      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:120)
      at acme.FooTest.doIt(FooTest.groovy:11)

      The attached archive project.zip is both a gradle and an eclipse project demonstrating the issue. I've produced it from scratch in order to closely reflect my real world scenario while limiting it to a bunch of classes and interfaces. However if you want I can probably further reduce it.
      BTW running FooTest.groovy from eclipse works fine, while from gradle (using jdk7) or from CLI it fails. As I said above also replacing the anonymous inner class with the map make the test work even with the jdk compiler.

      This issue could be related to GROOVY-6088, however I preferred to file it separately.

      Attachments

        1. project.zip
          5 kB
          Davide Cavestro

        Activity

          People

            Unassigned Unassigned
            davide.cavestro Davide Cavestro
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: