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

StackOverflowError Related To Trait Generics

    XMLWordPrintableJSON

    Details

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

      Description

      With the latest Groovy 2.4.1-SNAPSHOT the following code (attached as traitgenerics.zip) is problematic:

      src/main/groovy/demo/SomeTrait.groovy
      package demo
      
      trait SomeTrait {
          String title
          
          public <T> List<T> someMethod(T data) {}
      }
      

      This test will fail:

      src/test/groovy/demo/SomeTraitSpec.groovy
      package demo
      
      class SomeTraitSpec extends spock.lang.Specification {
      
          void 'test something'() {
              when:
              def sc = new Foo(title: 'some title')
      
              then:
              'some title' == sc.title
          }
      }
      
      class Foo implements SomeTrait {}
      

      The test fails because the call to the Foo constructor results in a StackOverflowError.

      java.lang.StackOverflowError
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:242)
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:243)
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:243)
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:243)
      
          ...
      
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:243)
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:243)
          at com.sun.beans.TypeResolver.erase(TypeResolver.java:274)
          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 demo.SomeTraitSpec.test something(SomeTraitSpec.groovy:7)
      

      I noticed that if the class which implements the trait (Foo in the example above) is defined under src/main/groovy along with the trait, everything seems to work. The problem only occurs if Foo is defined elsewhere. In the example above is defined under src/test/groovy.

        Attachments

        1. traitgenerics.zip
          50 kB
          Jeff Brown

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              brownj Jeff Brown
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: