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

CompileStatic stackoverflow with generic method with different placeholder as type argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.6, 2.5.0-beta-1
    • 2.4.6
    • Static compilation
    • None

    Description

      The fix in commit fae29119a for master and commit 197472cb for 2.4 branch corrected behavior that as a result can create a stackoverflow:

      To reproduce compile the following:

      @groovy.transform.CompileStatic
      class Foo {
          public <T> Class<T> firstClass(List<Class<T>> classes) {
              return classes.first()
          }
      }
      

      If you change the placeholder from T to E (the placeholder used by List) it compiles successfully. The StaticTypeCheckingSupport#applyGenericConnections method receives both E and T in the resolvePlaceholders map and because there is no connection and with the fix to equalIncludingGenerics a stackoverflow results.

      Stacktrace produced:

      java.lang.StackOverflowError
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.applyGenericsContext(StaticTypeCheckingSupport.java:1722)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.applyGenericsContext(StaticTypeCheckingSupport.java:1750)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.applyGenericsContext(StaticTypeCheckingSupport.java:1722)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.applyGenericsContext(StaticTypeCheckingSupport.java:1750)
      

      Found as a result of testing master against a Grails build and noticing a stackoverflow when compiling a method within GparsPromiseFactory

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            jwagenleitner John Wagenleitner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: