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


##########
src/main/java/org/apache/commons/jexl3/internal/Interpreter.java:
##########
@@ -1736,9 +1736,9 @@ private Object visit(final ASTMethodNode node, final 
Object antish, final Object
         for (int a = 1; a < node.jjtGetNumChildren(); ++a) {
             if (result == null) {
                 // no method, we fail// variable unknown in context and not a 
local
-                return node.isSafeLhs(isSafe())
+                return isSafeUndefined() && node.isSafeLhs(isSafe())
                         ? null
-                        : unsolvableMethod(methodNode, "<?>.<null>(...)");
+                        : unsolvableMethod(node, "<?>.<null>(...)");

Review Comment:
   This changed the error node passed into `unsolvableMethod(...)` from 
`methodNode` to `node`. That can reduce the precision of the exception location 
(and any node-based protection logic) since `node` spans the whole method 
expression/arguments. Prefer passing the most specific failing node (typically 
the member/method identifier node) for consistent error reporting and debugging.



##########
src/main/java/org/apache/commons/jexl3/internal/Interpreter.java:
##########
@@ -1721,7 +1721,7 @@ private Object visit(final ASTMethodNode node, final 
Object antish, final Object
                 object = data;
                 if (object == null) {
                     // no object, we fail
-                    return node.isSafeLhs(isSafe())
+                    return isSafe() || ((ASTIdentifierAccess) 
methodNode).isSafe()
                         ? null
                         : unsolvableMethod(methodNode, "<null>.<?>(...)");

Review Comment:
   This introduces a hard cast to ASTIdentifierAccess. If `methodNode` can ever 
be an `ASTArrayAccess` (eg member computed access like `x?['m']()` / 
functor-style calls), this will throw `ClassCastException` instead of honoring 
safe-navigation. Use the existing safe-access check (eg `isSafeAccess(...)`) or 
branch on the node type (identifier vs array access) rather than casting 
unconditionally.



##########
src/site/xdoc/reference/syntax.xml:
##########
@@ -291,6 +291,10 @@
                         In the previous expression,  if 'foo' is null, the 
whole expression will evaluate as null.
                         Note that this can also be used in a chain as in 
<code>x?[y]?[z]</code>.
                         </p>
+                        <p>Whether safe-access operators shortcut non-existent 
references - an undefined variable,
+                        property or method - as they do null is determined by 
the <code>safeUndefined</code> option,
+                        true by default; when false, only null is shortcut and 
a non-existent reference is an error.

Review Comment:
   The `safeUndefined` option also applies to undefined functions per the PR 
description/API docs. The user-facing syntax reference should include functions 
(and ideally mention consistency across properties/methods/array access) so 
readers don’t assume it only affects variables/properties/methods.



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