You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/11 09:06:45 UTC
groovy git commit: GROOVY-7880: Diamond Operator for own class causes
NullPointerException if Static Compilation is enabled (closes #382)
Repository: groovy
Updated Branches:
refs/heads/master 56a54b1eb -> b4a6095f5
GROOVY-7880: Diamond Operator for own class causes NullPointerException if Static Compilation is enabled (closes #382)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b4a6095f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b4a6095f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b4a6095f
Branch: refs/heads/master
Commit: b4a6095f54f632266a7e25413eb0b3baec7f8e01
Parents: 56a54b1
Author: paulk <pa...@asert.com.au>
Authored: Wed Aug 10 23:07:01 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Aug 11 19:06:10 2016 +1000
----------------------------------------------------------------------
.../stc/StaticTypeCheckingVisitor.java | 5 +-
.../groovy/transform/stc/Groovy7880Bug.groovy | 57 ++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/b4a6095f/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index ce7158e..e4a660b 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -783,7 +783,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
if (argumentListExpression.getExpressions().isEmpty()) {
GenericsType[] genericsTypes = lType.getGenericsTypes();
- if (lType.getGenericsTypes()==null) {
+ if (genericsTypes == null) {
// case of def foo = new HashMap<>()
genericsTypes = node.redirect().getGenericsTypes();
}
@@ -801,6 +801,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ClassNode type = getType(argumentListExpression.getExpression(0));
if (type.isUsingGenerics()) {
GenericsType[] genericsTypes = type.getGenericsTypes();
+ if (genericsTypes == null) {
+ genericsTypes = node.redirect().getGenericsTypes();
+ }
GenericsType[] copy = new GenericsType[genericsTypes.length];
for (int i = 0; i < genericsTypes.length; i++) {
GenericsType genericsType = genericsTypes[i];
http://git-wip-us.apache.org/repos/asf/groovy/blob/b4a6095f/src/test/groovy/transform/stc/Groovy7880Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy7880Bug.groovy b/src/test/groovy/transform/stc/Groovy7880Bug.groovy
new file mode 100644
index 0000000..033a550
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy7880Bug.groovy
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package groovy.transform.stc
+
+import gls.CompilableTestSupport
+
+class Groovy7880Bug extends CompilableTestSupport {
+ void testDiamondUseShouldNotCauseNPE() {
+ shouldCompile '''
+ @groovy.transform.CompileStatic
+ class BugTest {
+ private class CompilerKiller<T> {
+ private T t
+ CompilerKiller(T t){ this.t = t }
+ CompilerKiller(){ }
+ }
+
+ void "This works"(){
+ CompilerKiller<BugTest> sample = new CompilerKiller<BugTest>()
+ }
+
+ void "This previously caused a NPE"(){
+ CompilerKiller<BugTest> sample = new CompilerKiller<>(this)
+ }
+
+ void "This previously caused a NPE as well"(){
+ CompilerKiller<BugTest> sample = new CompilerKiller<>(new BugTest())
+ }
+
+ void "This does work"(){
+ CompilerKiller<BugTest> sample = new CompilerKiller<BugTest>(this)
+ }
+
+ void "This works as well"(){
+ CompilerKiller<BugTest> sample = new CompilerKiller(this)
+ }
+ }
+ '''
+ }
+}