修复 B1 JUEL 致命缺陷:resolveBindings 触 FlowScriptBindings.entrySet UOE(dogfooding 实证)
逐流写 QA dogfooding + 上一提交的 gracefulFlowError 栈日志联合暴露:JuelScriptEngine.resolveBindings
用 SimpleBindings.putAll 合并入参 bindings,而真实服务流传入的是保真层 FlowScriptBindings——其
entrySet/keySet/putAll/size/values 抛 UnsupportedOperationException(仅 get/put/containsKey 实现,
架构设计§1 早记)。致【所有带 conditionExpression 的 EL 写流】在转移求值(${isSave} 等)时崩。
B2 差分用 SimpleBindings(entrySet 正常)故漏检;线性流(通知 OA_NOTICEMANAGE_ADD,无条件转移)
恰好不触发,致先前误判端到端已通。
修:废 resolveBindings 的 putAll 复制;BindingsELResolver 改持 ENGINE/GLOBAL 两层 Bindings,
顶层变量惰性 lookup 仅用 containsKey()+get()(FlowScriptBindings 支持的方法),不复制不遍历。
新增回归测试 (g):FlowScriptBindingsLike(entrySet/putAll 抛 UOE)下 ${x+1}/${isSave}/${x>3}/${nope}
均正确求值。platform-app 9 测试全绿(B2 差分 1376 等价仍不回归)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,7 +63,12 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ELContext elContext = new BindingsELContext(resolveBindings(context));
|
||||
// 直接持有 ENGINE/GLOBAL 两层 Bindings,经 ELResolver 惰性 get() 解析顶层变量——
|
||||
// 不可 putAll/复制:真实服务流传入的 FlowScriptBindings 的 entrySet/keySet/putAll
|
||||
// 抛 UnsupportedOperationException(仅 get/put/containsKey 可用),复制会崩(QA dogfooding 实证)。
|
||||
ELContext elContext = new BindingsELContext(
|
||||
context.getBindings(ScriptContext.ENGINE_SCOPE),
|
||||
context.getBindings(ScriptContext.GLOBAL_SCOPE));
|
||||
ValueExpression expr = EXPRESSION_FACTORY.createValueExpression(elContext, script, Object.class);
|
||||
return expr.getValue(elContext);
|
||||
} catch (ELException e) {
|
||||
@@ -96,24 +101,6 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并 ENGINE_SCOPE 与 GLOBAL_SCOPE 的 bindings(ENGINE_SCOPE 优先),作为 EL 顶层变量来源。
|
||||
* 与 framework 行为一致:调用方经 {@code evaluate(script, "juel", bindings)} 传入的
|
||||
* bindings 落在 ENGINE_SCOPE。
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private Map<String, Object> resolveBindings(ScriptContext context) {
|
||||
SimpleBindings merged = new SimpleBindings();
|
||||
Bindings global = context.getBindings(ScriptContext.GLOBAL_SCOPE);
|
||||
if (global != null) {
|
||||
merged.putAll(global);
|
||||
}
|
||||
Bindings engine = context.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
if (engine != null) {
|
||||
merged.putAll(engine);
|
||||
}
|
||||
return (Map) merged;
|
||||
}
|
||||
|
||||
private static String readFully(Reader reader) throws ScriptException {
|
||||
if (reader == null) {
|
||||
@@ -162,9 +149,9 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
private final VariableMapper variableMapper = new NoopVariableMapper();
|
||||
private final FunctionMapper functionMapper = new NoopFunctionMapper();
|
||||
|
||||
private BindingsELContext(Map<String, Object> bindings) {
|
||||
private BindingsELContext(Bindings engineBindings, Bindings globalBindings) {
|
||||
CompositeELResolver composite = new CompositeELResolver();
|
||||
composite.add(new BindingsELResolver(bindings));
|
||||
composite.add(new BindingsELResolver(engineBindings, globalBindings));
|
||||
composite.add(new MapELResolver());
|
||||
composite.add(new ListELResolver());
|
||||
composite.add(new ArrayELResolver());
|
||||
@@ -201,17 +188,34 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
*/
|
||||
private static final class BindingsELResolver extends ELResolver {
|
||||
|
||||
private final Map<String, Object> bindings;
|
||||
private final Bindings engineBindings;
|
||||
private final Bindings globalBindings;
|
||||
|
||||
private BindingsELResolver(Map<String, Object> bindings) {
|
||||
this.bindings = bindings;
|
||||
private BindingsELResolver(Bindings engineBindings, Bindings globalBindings) {
|
||||
this.engineBindings = engineBindings;
|
||||
this.globalBindings = globalBindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅用 {@code get()/containsKey()} 解析顶层变量(ENGINE 优先,缺则 GLOBAL)。
|
||||
* 关键:严禁 entrySet/keySet/putAll——真实服务流的 FlowScriptBindings 这些方法抛
|
||||
* UnsupportedOperationException,仅 get/put/containsKey 实现(QA dogfooding 实证)。
|
||||
*/
|
||||
private Object lookup(String name) {
|
||||
if (engineBindings != null && engineBindings.containsKey(name)) {
|
||||
return engineBindings.get(name);
|
||||
}
|
||||
if (globalBindings != null && globalBindings.containsKey(name)) {
|
||||
return globalBindings.get(name);
|
||||
}
|
||||
return null; // 未绑定 → null(保持 JUEL 宽松语义)
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(ELContext context, Object base, Object property) {
|
||||
if (base == null && property instanceof String) {
|
||||
context.setPropertyResolved(true);
|
||||
return bindings.get(property);
|
||||
return lookup((String) property);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -220,7 +224,7 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
public Class<?> getType(ELContext context, Object base, Object property) {
|
||||
if (base == null && property instanceof String) {
|
||||
context.setPropertyResolved(true);
|
||||
Object value = bindings.get(property);
|
||||
Object value = lookup((String) property);
|
||||
return value == null ? Object.class : value.getClass();
|
||||
}
|
||||
return null;
|
||||
@@ -230,7 +234,9 @@ public class JuelScriptEngine extends AbstractScriptEngine implements Compilable
|
||||
public void setValue(ELContext context, Object base, Object property, Object value) {
|
||||
if (base == null && property instanceof String) {
|
||||
context.setPropertyResolved(true);
|
||||
bindings.put((String) property, value);
|
||||
if (engineBindings != null) {
|
||||
engineBindings.put((String) property, value); // put 可用
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user