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 03:58:24 UTC
[groovy] 02/03: GROOVY-10743: The use method for Category classes can't take an interface with static methods due to a NPE (port to 3_0_X)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 6b04a734a645a0fb27f907e0567acef3f5362a4e
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 (port to 3_0_X)
---
.../org/codehaus/groovy/runtime/GroovyCategorySupport.java | 4 ++--
src/test/groovy/CategoryTest.groovy | 13 +++++++++++++
2 files changed, 15 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 ff872fc56f..8a05c8e0e5 100644
--- a/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/GroovyCategorySupport.java
@@ -184,8 +184,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 2a7f73f276..32d53f1af5 100644
--- a/src/test/groovy/CategoryTest.groovy
+++ b/src/test/groovy/CategoryTest.groovy
@@ -20,6 +20,8 @@ package groovy
import groovy.test.GroovyTestCase
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
final class CategoryTest extends GroovyTestCase {
void setUp() {
@@ -262,6 +264,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()