Copilot commented on code in PR #402:
URL: https://github.com/apache/commons-jexl/pull/402#discussion_r3309689448
##########
src/main/java/org/apache/commons/jexl3/JexlArithmetic.java:
##########
@@ -1005,6 +1007,32 @@ protected Object increment(final Object val, final int
incr) {
throw new ArithmeticException("Object "+(incr < 0?
"decrement":"increment")+":(" + val + ")");
}
+ /**
+ * Evaluates a supplier argument, eventually catching and logging any
JexlException.
+ *
+ * <p>Used primarily by {@link #empty(Object)} and {@link #size(Object)}
to guard argument evaluation.
+ * If evaluation succeeds, returns the supplier's result. If a {@link
JexlException} occurs, logs a
+ * warning and returns the supplier itself.</p>
+ *
+ * <p>This method is public to allow overriding. Implementations that
change the exception handling
+ * behavior must still return the supplier on failure to maintain the
contract.</p>
+ *
+ * @param logger the logger for warning messages; may be null
+ * @param arg the supplier providing the argument to evaluate
+ * @return the evaluated result on success, or the supplier itself on
JexlException
+ * @since 3.6.3
+ */
+ public Object evaluate(Log logger, Supplier<Object> arg) {
+ try {
+ return arg.get();
+ } catch (JexlException e) {
+ if (logger != null && logger.isWarnEnabled()) {
+ logger.warn(e.getMessage(), e);
Review Comment:
Logging uses `logger.warn(e.getMessage(), e)`, which logs the full
`JexlException` stack trace; elsewhere in the codebase warning logs typically
use `xjexl.getCause()` to surface the underlying exception. Consider logging
`e.getCause()` (falling back to `e` when null) to make the warning more
actionable and consistent with existing engine/interpreter logging.
##########
src/test/java/org/apache/commons/jexl3/Issues400Test.java:
##########
@@ -1183,5 +1183,20 @@ void testIssue36x_456_let() {
assertEquals("42", writer.toString());
}
+
+ @Test
+ void test459() {
+ CaptureLog capture = new CaptureLog("test459");
+ final JexlBuilder builder = new
JexlBuilder().logger(capture).safe(true).strict(false).silent(true);
+ final JexlEngine jexl = builder.create();
+ String expr = "empty('aaa'.substring(400,500))";
+ JexlScript script = jexl.createScript(expr);
+ Object result = script.execute(null);
+ assertEquals(true, result);
+ List<String> errors = capture.getCapturedMessages();
+ assertEquals(1, errors.size());
+ assertTrue(errors.get(0).contains("substring"));
Review Comment:
`CaptureLog#getCapturedMessages()` returns messages from all log levels, so
asserting `errors.size() == 1` can be brittle if additional debug/info messages
are emitted during evaluation. Consider asserting the warn count via
`capture.count("warn")` and then checking the warn message(s) specifically (or
filtering to warn entries) so the test only fails when the warn logging
behavior under test changes.
--
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]