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 2022/09/03 02:17:50 UTC
[groovy] 02/03: GROOVY-10743: The use method for Category classes can't take an interface with static methods due to a NPE
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 9c6d6cbb6a8e2e4e8abe03b28500dea4ae8b319b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Sep 2 12:55:40 2022 +1000
GROOVY-10743: The use method for Category classes can't take an interface with static methods due to a NPE
---
.../org/codehaus/groovy/runtime/GroovyCategorySupport.java | 4 ++--
src/test/groovy/CategoryTest.groovy | 14 ++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
index bc1493a12e..000bfc252a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
@@ -188,8 +188,8 @@ public class GroovyCategorySupport {
private void use(Class categoryClass) {
CachedClass cachedClass = ReflectionCache.getCachedClass(categoryClass);
- LinkedList<CachedClass> classStack = new LinkedList<CachedClass>();
- for (CachedClass superClass = cachedClass; superClass.getTheClass()!=Object.class; superClass = superClass.getCachedSuperClass()) {
+ LinkedList<CachedClass> classStack = new LinkedList<>();
+ for (CachedClass superClass = cachedClass; superClass != null && superClass.getTheClass() != Object.class; superClass = superClass.getCachedSuperClass()) {
classStack.add(superClass);
}
diff --git a/src/test/groovy/CategoryTest.groovy b/src/test/groovy/CategoryTest.groovy
index 92a734668c..f8c0a0f2a7 100644
--- a/src/test/groovy/CategoryTest.groovy
+++ b/src/test/groovy/CategoryTest.groovy
@@ -20,6 +20,9 @@ package groovy
import groovy.test.GroovyTestCase
+import static groovy.test.GroovyAssert.isAtLeastJdk
+import static org.junit.Assume.assumeTrue
+
final class CategoryTest extends GroovyTestCase {
@Override
@@ -327,6 +330,17 @@ final class CategoryTest extends GroovyTestCase {
'''
}
+ // GROOVY-10743
+ void testStaticMethodOnInterface() {
+ if(!isAtLeastJdk('9.0')) return
+ assertScript '''
+ use(java.util.stream.Stream) {
+ assert [1, 1].iterate(f -> [f[1], f.sum()]).limit(8).toList()*.head() == [1, 1, 2, 3, 5, 8, 13, 21]
+ assert 16.iterate(n -> n < 500, n -> n * 2).toList() == [16, 32, 64, 128, 256]
+ }
+ '''
+ }
+
// GROOVY-3867
void testPropertyMissing() {
def x = new X()