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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5af35b2  GROOVY-10184: fix for NPE
5af35b2 is described below

commit 5af35b26264de7146b126974d4398616bb71a3aa
Author: Eric Milles <[email protected]>
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 8d60be4..ac3dbda 100644
--- 
a/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
+++ 
b/src/main/java/org/codehaus/groovy/control/customizers/SecureASTCustomizer.java
@@ -1013,7 +1013,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()')
-    }
 }

Reply via email to