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


##########
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:
   The changelog entry describes the *buggy* behavior as if it were the current 
behavior. Since this is a fix entry, please reword it to describe the corrected 
behavior (that interpolations are parsed with the script’s features rather than 
the engine’s).



##########
src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java:
##########
@@ -912,24 +916,38 @@ public JxltEngine.Expression createExpression(final 
JexlInfo jexlInfo, final Str
     }
 
     public JxltEngine.Expression createExpression(final JexlInfo jexlInfo, 
final String expression, final Scope scope) {
+        return createExpression(jexlInfo, expression, scope, null);
+    }
+
+    /**
+     * Creates an expression that is embedded in a script, an interpolation.
+     *
+     * @param jexlInfo   The source info
+     * @param expression The expression source
+     * @param scope      The scope
+     * @param ftrs       The features of the script the expression is embedded 
in, null for those of the engine
+     * @return The expression
+     */
+    public JxltEngine.Expression createExpression(final JexlInfo jexlInfo, 
final String expression, final Scope scope,
+                                                  final JexlFeatures ftrs) {
         final JexlInfo info = jexlInfo == null ?  jexl.createInfo() : jexlInfo;
         Exception xuel = null;
         TemplateExpression stmt = null;
-        final JexlFeatures features = noscript ? jexl.expressionFeatures : 
jexl.scriptFeatures;
+        final JexlFeatures features = features(ftrs);
         // do not cache interpolation expression, they are stored in AST node

Review Comment:
   The comment says interpolations are not cached, but the code clearly enables 
caching when `cached` is true (and the PR description/tests explicitly rely on 
correct cache keying by features). Please update or remove the comment so it 
accurately reflects the current caching behavior.



##########
src/main/java/org/apache/commons/jexl3/parser/JexlParser.java:
##########
@@ -1170,16 +1170,18 @@ public ASTJexlScript jxltParse(final JexlInfo info, 
final JexlFeatures features,
      * @param info The JexlInfo
      * @param src The source to parse
      * @param scope The scope
+     * @param features The features of the script the expression is embedded in
      * @return The expression
      */
-    static JxltEngine.Expression parseInterpolation(final JexlInfo info, final 
String src, final Scope scope) {
+    static JxltEngine.Expression parseInterpolation(final JexlInfo info, final 
String src, final Scope scope,
+                                                    final JexlFeatures 
features) {
         final JexlEngine jexl = JexlEngine.getThreadEngine();
         if (jexl != null) {
             // interpolation uses default $ and # as expression markers;
             // the cache size is negative to reuse the engine cache
             final JxltEngine jxlt = jexl.createJxltEngine(true, -1, '$', '#');
             if (jxlt instanceof TemplateEngine) {
-                return ((TemplateEngine) jxlt).createExpression(info, src, 
scope);
+                return ((TemplateEngine) jxlt).createExpression(info, src, 
scope, features);
             }
         }
         throw new IllegalStateException("engine is not a accessible");

Review Comment:
   The exception message has a grammatical error (\"a accessible\"). Consider 
changing it to a clearer message like \"engine is not accessible\" or (more 
specific) \"no thread-local engine available\" to improve diagnosability.



##########
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:
   The helper method name `features(...)` is ambiguous and easy to confuse with 
local variables named `features` (as used in `createExpression`). Renaming this 
helper to something like `effectiveFeatures(...)` / `normalizeFeatures(...)` 
would improve readability.



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