henrib commented on code in PR #427:
URL: https://github.com/apache/commons-jexl/pull/427#discussion_r4574759609


##########
src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java:
##########
@@ -987,7 +1005,35 @@ char getImmediateChar() {
      * @return The unified expression instance
      * @throws JexlException if an error occurs during parsing
      */
-    TemplateExpression parseExpression(final JexlInfo info, final String expr, 
final Scope scope) {  // CSOFF: MethodLength
+    TemplateExpression parseExpression(final JexlInfo info, final String expr, 
final Scope scope) {
+        return parseExpression(info, expr, scope, features(null));
+    }
+
+    /**
+     * Gets the features used to parse the JEXL expressions of a unified 
expression.
+     *
+     * @param ftrs The features of the script the unified expression is 
embedded in, null for those of the engine
+     * @return The features
+     */
+    private JexlFeatures features(final JexlFeatures ftrs) {
+        if (ftrs == null) {
+            return noscript ? jexl.expressionFeatures : jexl.scriptFeatures;
+        }
+        return noscript && ftrs.supportsScript() ? new 
JexlFeatures(ftrs).script(false) : ftrs;
+    }

Review Comment:
   This is not a hot path: the features are derived when the parser builds an 
interpolation node, once per node, and evaluation uses the expression stored in 
the node. Still, scripts created with the features of the engine did not need a 
copy before this change; e0f00f2b reuses the engine expression features for 
them, so only scripts created with their own features derive one.



##########
src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java:
##########
@@ -377,9 +377,19 @@ void testMany() throws Exception {
 
                 // attempt to force GC:
                 // while we still have a MB free, create & store big objects
-                for (int b = 0; b < 1024 && Runtime.getRuntime().freeMemory() 
> MEGA; ++b) {
-                    final BigObject big = new BigObject(b);
-                    stuff.add(new InstanceReference(big, queue));
+                try {
+                    for (int b = 0; b < 1024 && 
Runtime.getRuntime().freeMemory() > MEGA; ++b) {
+                        final BigObject big = new BigObject(b);
+                        stuff.add(new InstanceReference(big, queue));
+                    }
+                } catch (final OutOfMemoryError oom) {
+                    // exhausting the heap is the intent; if the JVM fails an 
allocation instead of
+                    // clearing the soft references, release the big objects 
and carry on
+                    for (final Reference<?> soft : stuff) {
+                        if (soft instanceof InstanceReference) {
+                            soft.clear();
+                        }
+                    }
                 }

Review Comment:
   Kept as is: what the test asserts is unchanged, a generated class must be 
collected and reloaded (`gced >= 0`, second pass). Filling the heap is only a 
means to provoke a GC, and the clearing of soft references is the JVM's 
business, not what is under test.



##########
src/changes/changes.xml:
##########
@@ -29,6 +29,7 @@
     <body>
         <release version="3.7.2" date="YYYY-MM-DD" description="This is a 
feature and maintenance release. Java 8 or later is required.">
             <!-- FIX -->
+            <action dev="henrib" due-to="Claude" type="fix" 
issue="JEXL-477">Interpolation strings are parsed with the engine features 
instead of those of their script.</action>

Review Comment:
   Kept as is, same as the earlier thread: in this file, fix entries state the 
problem as the JIRA title does.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to