You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Frank Pavageau (JIRA)" <ji...@apache.org> on 2016/02/02 23:48:39 UTC

[jira] [Commented] (GROOVY-7742) CompileStatic stackoverflow with generic method with different placeholder as type argument

    [ https://issues.apache.org/jira/browse/GROOVY-7742?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15129231#comment-15129231 ] 

Frank Pavageau commented on GROOVY-7742:
----------------------------------------

Chiming in as the author of the fix, which I did after finding the incorrect code while debugging something else. I'd unsuccessfully tried to create a synthetic test case showing the effect of the fix, which [~blackdrag] had asked for, I'd even wondered if the code was actually used at all.

I've spent quite some time recently in the handling of generics in the static type checker, and I'd already noticed there probably were lingering issues with the way placeholders are managed, e.g. using a single flattened context (mapping of the placeholders) instead of more isolated ones (I'm probably thinking of {{GenericsUtils.extractPlaceholders()}}). GROOVY-7719 and GROOVY-5839 could be some of those.

I'll see if I can find something tomorrow. Of course, the fix can also be reverted until a more complete solution addressing this new bug is found, since Groovy had the incorrect code for quite a while without anyone noticing.

> CompileStatic stackoverflow with generic method with different placeholder as type argument
> -------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7742
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7742
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.6, 2.5.0-beta-1
>            Reporter: John Wagenleitner
>            Priority: Blocker
>
> The fix in [commit fae29119a|https://github.com/apache/groovy/commit/fae29119a1102393ae5d1645c3fc1e06547b0ad8] for master and [commit 197472cb|https://github.com/apache/groovy/commit/197472cb626bdada5e079c7f0cd145b85502f034] for 2.4 branch corrected behavior that as a result can create a stackoverflow:
> To reproduce compile the following:
> {code}
> @groovy.transform.CompileStatic
> class Foo {
>     public <T> Class<T> firstClass(List<Class<T>> classes) {
>         return classes.first()
>     }
> }
> {code}
> If you change the placeholder from {{T}} to {{E}} (the placeholder used by List) it compiles successfully.  The [{{StaticTypeCheckingSupport#applyGenericConnections}} method |https://github.com/apache/groovy/blob/d6bb5b8ff84b57c2c337c3db5008103b7c6d13d5/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java#L1509] 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:
> {code}
> 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)
> {code}
> Found as a result of testing master against a Grails build and noticing a stackoverflow when compiling [a method within GparsPromiseFactory|https://github.com/jwagenleitner/grails-core/blob/69e7bb967fb8e8e331927cf2521b48cea93ee059/grails-async/src/main/groovy/org/grails/async/factory/gpars/GparsPromiseFactory.groovy#L106-L109]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)