You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/04/16 18:31:00 UTC

[jira] [Comment Edited] (GROOVY-9079) STC: NPE in StaticTypeCheckingVisitor.inferSAMTypeGenericsInAssignment

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

Eric Milles edited comment on GROOVY-9079 at 4/16/19 6:30 PM:
--------------------------------------------------------------

One suggestion for ClosureExpression: add method {{Optional<List<Parameter>> getParameterList()}}.  The {{Optional.isAbsent()}} case should stand for "\{ \}" and a list of size 0 for "\{ -> \}" and of course a list of size 1 or more for "\{ param, ... -> \}".  To me this is much more consistent than the current null vs. non-null distinction of {{getParameters()}}.  And it would provide the opportunity to return an unmodifiable list, instead of the internal array reference.


was (Author: emilles):
One suggestion for ClosureExpression: add method {{Optional<List<Parameter>> getParameterList()}}.  The {{Optional.isAbsent()}} case should stand for "\{ \}" and a list of size 0 for "\{ -> \}" and of course a list of size 1 or more for "\{ arg, ... -> \}".  To me this is much more consistent than the current null vs. non-null distinction of {{getParameters()}}.  And it would provide the opportunity to return an unmodifiable list, instead of the internal array reference.

> STC: NPE in StaticTypeCheckingVisitor.inferSAMTypeGenericsInAssignment
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-9079
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9079
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 3.0.0-beta-1, 2.5.7
>
>
> Consider the following:
> {code:groovy}
> @groovy.transform.CompileStatic
> void meth() {
>   java.util.concurrent.Callable<String> call = { -> '' }
> }
> {code}
> This code produces:
> {code}
> BUG! exception in phase 'instruction selection' in source unit 'Blah.groovy' unexpected NullpointerException
> 	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1148)
> 	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:654)
> 	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:632)
> 	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:609)
> 	...
> Caused by: java.lang.NullPointerException
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferSAMTypeGenericsInAssignment(StaticTypeCheckingVisitor.java:4282)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.getResultType(StaticTypeCheckingVisitor.java:4133)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:831)
> 	...
> {code}
> The method in StaticTypeCheckingVisitor calls ClosureExpression.getParameters(), which returns null for a closure expression like "{ -> '' }".



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)