You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/01/30 18:53:52 UTC

[groovy] 02/02: GROOVY-10184: fix for NPE

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 7d21ea5eec724c088970f3e104c195c3f8822b78
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Sep 28 09:47:54 2021 -0500

    GROOVY-10184: fix for NPE
---
 .../control/customizers/SecureASTCustomizer.java   |  2 +-
 .../customizers/SecureASTCustomizerTest.groovy     | 32 ++++++++++++++--------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java b/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
index ad8ed7a..74594d2 100644
--- a/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
+++ b/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
@@ -974,7 +974,7 @@ public class SecureASTCustomizer extends CompilationCustomizer {
     }
 
     protected void assertStaticImportIsAllowed(final String member, final String className) {
-        final String fqn = member.equals(className) ? member : className + "." + member;
+        final String fqn = className.equals(member) ? className : className + "." + member;
         if (allowedStaticImports != null && !allowedStaticImports.contains(fqn)) {
             if (allowedStaticStarImports != null) {
                 // we should now check if the import is in the star imports
diff --git a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
index 973c00b..1edb459 100644
--- a/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
+++ b/src/test/org/codehaus/groovy/control/customizers/SecureASTCustomizerTest.groovy
@@ -357,7 +357,7 @@ final class SecureASTCustomizerTest {
     }
 
     @Test
-    void testAllowedIndirectStarImports() {
+    void testAllowedIndirectStarImports1() {
         customizer.allowedStarImports = ['java.util.*']
         customizer.indirectImportCheckEnabled = true
         def shell = new GroovyShell(configuration)
@@ -380,6 +380,25 @@ final class SecureASTCustomizerTest {
         }
     }
 
+    @Test // GROOVY-8135
+    void testAllowedIndirectStarImports2() {
+        customizer.allowedStarImports = ['java.lang']
+        customizer.indirectImportCheckEnabled = true
+        def shell = new GroovyShell(configuration)
+        shell.evaluate('Object object = new Object()')
+        shell.evaluate('Object object = new Object(); object.hashCode()')
+        shell.evaluate('Object[] array = new Object[0]; array.size()')
+        shell.evaluate('Object[][] array = new Object[0][0]; array.size()')
+    }
+
+    @Test // GROOVY-10184
+    void testAllowedIndirectStarImports3() {
+        customizer.allowedStarImports = ['java.lang.*']
+        customizer.indirectImportCheckEnabled = true
+        def shell = new GroovyShell(configuration)
+        shell.evaluate('def obj = new Object(); def method = "hashCode"; obj."${method}"()')
+    }
+
     @Test
     void testAllowedStaticImports() {
         customizer.allowedStaticImports = ['java.lang.Math.PI']
@@ -601,15 +620,4 @@ final class SecureASTCustomizerTest {
             '''
         }
     }
-
-    @Test // GROOVY-8135
-    void testStarImportsAllowedListWithIndirectImportCheckEnabled() {
-        customizer.indirectImportCheckEnabled = true
-        customizer.allowedStarImports = ['java.lang']
-        def shell = new GroovyShell(configuration)
-        shell.evaluate('Object object = new Object()')
-        shell.evaluate('Object object = new Object(); object.hashCode()')
-        shell.evaluate('Object[] array = new Object[0]; array.size()')
-        shell.evaluate('Object[][] array = new Object[0][0]; array.size()')
-    }
 }