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


##########
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:
   This release note reads like the *current* behavior is still incorrect (“are 
parsed with… instead of…”). To reflect the fix, reword to indicate the previous 
behavior (“were parsed…”) or the new behavior (“are now parsed with their 
script features rather than the engine features”).



##########
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:
   Catching `OutOfMemoryError` and then continuing can make this test pass even 
when the expected behavior (soft references being cleared under pressure) does 
not occur, potentially masking regressions. Consider turning the 
`OutOfMemoryError` path into a skipped/inconclusive test (e.g., via JUnit 
assumptions) or failing with a clear message after cleanup, so an OOM doesn’t 
silently reduce the test’s assertion strength.



##########
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:
   When `noscript && ftrs.supportsScript()` is true, this allocates a new 
`JexlFeatures` instance for every embedded expression creation. If 
interpolations are frequent, this can become allocation-heavy. A concrete 
improvement would be to derive the ‘expression’ features once per embedding 
script (or once per AST interpolation node) and pass/store that derived 
instance, avoiding repeated cloning in hot paths.



-- 
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