Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Cannot Reproduce
-
2.4.12
-
None
-
None
-
None
Description
I am seeing this NPE due to one of our Groovy sources. When I replace the defaults below with additional constructors, the error subsides.
@CompileStatic class Foo implements Comparable<Foo> { Foo(String id = null, List<Bar> bars = Collections.EMPTY_LIST) { ... } }
Caused by: java.lang.NullPointerException at org.codehaus.groovy.control.StaticVerifier$1.visitVariableExpression(StaticVerifier.java:96) at org.codehaus.groovy.ast.expr.VariableExpression.visit(VariableExpression.java:72) at org.codehaus.groovy.ast.CodeVisitorSupport.visitPropertyExpression(CodeVisitorSupport.java:254) at org.codehaus.groovy.ast.expr.PropertyExpression.visit(PropertyExpression.java:57) at org.codehaus.groovy.control.StaticVerifier.visitConstructorOrMethod(StaticVerifier.java:91) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:166) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1197) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:56) at org.codehaus.groovy.control.StaticVerifier.visitClass(StaticVerifier.java:54) at org.codehaus.groovy.control.CompilationUnit$13.call(CompilationUnit.java:228) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1129)
Line 96 is the last line of:
@Override public void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { MethodNode oldCurrentMethod = currentMethod; currentMethod = node; super.visitConstructorOrMethod(node, isConstructor); if (isConstructor) { final Set<String> exceptions = new HashSet<String>(); for (final Parameter param : node.getParameters()) { exceptions.add(param.getName()); if (param.hasInitialExpression()) { param.getInitialExpression().visit(new CodeVisitorSupport() { @Override public void visitVariableExpression(VariableExpression ve) { if (exceptions.contains(ve.getName())) return; Variable av = ve.getAccessedVariable(); if (av instanceof DynamicVariable || !av.isInStaticContext()) {