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/10/10 16:46:49 UTC

[groovy] branch GROOVY_4_0_X updated: sync with 3_0_X

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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 11b5a1564f sync with 3_0_X
11b5a1564f is described below

commit 11b5a1564f7ca8bbea12a02c0ddd9eab538e2fb3
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Oct 10 10:24:24 2022 -0500

    sync with 3_0_X
---
 .../transform/stc/StaticTypeCheckingSupport.java   | 26 +++++++++++-----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index d935d6f81c..1868c00438 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -2215,26 +2215,26 @@ public abstract class StaticTypeCheckingSupport {
                 return ((ListExpression) ce).getExpressions().stream().map(e -> evaluateExpression(e, config)).toArray(String[]::new);
         }
 
-        String className = "Expression$" + UUID.randomUUID().toString().replace('-', '$');
-        ClassNode simpleClass = new ClassNode(className, Opcodes.ACC_PUBLIC, OBJECT_TYPE);
-        addGeneratedMethod(simpleClass, "eval", Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new ReturnStatement(expr));
+        String className = "Expression$"+UUID.randomUUID().toString().replace('-', '$');
+        ClassNode classNode = new ClassNode(className, Opcodes.ACC_PUBLIC, OBJECT_TYPE);
+        addGeneratedMethod(classNode, "eval", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new ReturnStatement(expr));
 
-        // adjust configuration so class can be inspected by this JVM
+        // adjust configuration so class can be executed by this JVM
         CompilerConfiguration cc = new CompilerConfiguration(config);
-        cc.setPreviewFeatures(false); // unlikely to be required by expression
+        cc.setPreviewFeatures(false);
+        cc.setScriptBaseClass(null);
         cc.setTargetBytecode(CompilerConfiguration.DEFAULT.getTargetBytecode());
 
         CompilationUnit cu = new CompilationUnit(cc);
         try {
-            cu.addClassNode(simpleClass);
+            cu.addClassNode(classNode);
             cu.compile(Phases.CLASS_GENERATION);
-            List<GroovyClass> classes = cu.getClasses();
-            Class<?> aClass = cu.getClassLoader().defineClass(className, classes.get(0).getBytes());
-            try {
-                return aClass.getMethod("eval").invoke(null);
-            } catch (ReflectiveOperationException e) {
-                throw new GroovyBugError(e);
-            }
+            GroovyClass gc = cu.getClasses().get(0);
+            Class<?> c = cu.getClassLoader().defineClass(className, gc.getBytes());
+            // invoke method to produce return value
+            return c.getMethod("eval").invoke(null);
+        } catch (ReflectiveOperationException e) {
+            throw new GroovyBugError(e);
         } finally {
             closeQuietly(cu.getClassLoader());
         }