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/11 21:23:01 UTC
[jira] [Commented] (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=16815787#comment-16815787 ]
Eric Milles commented on GROOVY-9079:
-------------------------------------
This can be fixed with a guard condition:
{code:java}
private ClassNode inferSAMTypeGenericsInAssignment(ClassNode samUsage, MethodNode sam, ClassNode closureType, ClosureExpression closureExpression) {
// if the sam type or closure type do not provide generics information,
// we cannot infer anything, thus we simply return the provided samUsage
GenericsType[] samGt = samUsage.getGenericsTypes();
GenericsType[] closureGt = closureType.getGenericsTypes();
if (samGt == null || closureGt == null) return samUsage;
// extract the generics from the return type
Map<GenericsTypeName, GenericsType> connections = new HashMap<GenericsTypeName, GenericsType>();
extractGenericsConnections(connections, getInferredReturnType(closureExpression), sam.getReturnType());
// GRECLIPSE add
if (closureExpression.isParameterSpecified()) {
// GRECLIPSE end
// next we get the block parameter types and set the generics
// information just like before
// TODO: add vargs handling
Parameter[] closureParams = closureExpression.getParameters();
Parameter[] methodParams = sam.getParameters();
for (int i = 0; i < closureParams.length; i++) {
ClassNode fromClosure = closureParams[i].getType();
ClassNode fromMethod = methodParams[i].getType();
extractGenericsConnections(connections, fromClosure, fromMethod);
}
// GRECLIPSE add
}
// GRECLIPSE end
ClassNode result = applyGenericsContext(connections, samUsage.redirect());
return result;
}
{code}
There may also be a latent NPE in the AutoFinal xform, which uses ClosureExpression.getParameters() unguarded as well.
> 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
> Priority: Major
>
> 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)