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


##########
src/main/java/org/apache/commons/jexl3/internal/Engine.java:
##########
@@ -528,6 +532,10 @@ protected JexlOptions evalOptions(final ASTJexlScript 
script, final JexlContext
             if (scriptFeatures.supportsConstCapture()) {
                 opts.setConstCapture(true);
             }
+            // downgrade only: a feature that forbids namespace 
auto-instantiation wins
+            if (!scriptFeatures.supportsNamespaceInstantiation()) {
+                opts.setNamespaceInstantiation(false);
+            }

Review Comment:
   This downgrade runs before `processPragmas` below, but `#pragma jexl.options 
'+namespaceInstantiation'` is accepted by the new option flag and sets it back 
to true. A script parsed with this feature disabled can therefore still invoke 
a namespace constructor (and a shared engine option can remain enabled for 
later scripts). Reapply the feature restriction after pragma processing, 
unconditionally, so pragmas cannot override it.



##########
src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java:
##########
@@ -906,8 +906,10 @@ protected Object resolveNamespace(final String prefix, 
final JexlNode node) {
             if (cached instanceof Class<?>) {
                 return cached;
             }
+            // whether reflective auto-instantiation of a functor is allowed 
for this namespace
+            final boolean instantiate = options.isNamespaceInstantiation();
             // attempt to reuse last cached constructor
-            if (cached instanceof JexlContext.NamespaceFunctor) {
+            if (instantiate && cached instanceof JexlContext.NamespaceFunctor) 
{

Review Comment:
   Because the `cached instanceof Class<?>` fast path returns before the new 
option is checked, a script first executed with `namespaceInstantiation` 
disabled caches the class as static-only; a later execution with the same 
script and the option enabled can never try its constructor. Check the option 
before this cache hit (or avoid caching this result in the disabled mode) so 
per-evaluation `JexlOptions` can take effect.



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