修复 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:
@@ -126,4 +126,32 @@ class JuelScriptEngineSeamTest {
|
||||
assertTrue(result instanceof Number);
|
||||
assertEquals(6, ((Number) result).intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟保真层 FlowScriptBindings:get/put/containsKey 可用,
|
||||
* entrySet/keySet/values/size/putAll 抛 UnsupportedOperationException(与真实类一致)。
|
||||
*/
|
||||
static class FlowScriptBindingsLike extends SimpleBindings {
|
||||
@Override public java.util.Set<java.util.Map.Entry<String, Object>> entrySet() { throw new UnsupportedOperationException(); }
|
||||
@Override public java.util.Set<String> keySet() { throw new UnsupportedOperationException(); }
|
||||
@Override public java.util.Collection<Object> values() { throw new UnsupportedOperationException(); }
|
||||
@Override public int size() { throw new UnsupportedOperationException(); }
|
||||
@Override public void putAll(java.util.Map<? extends String, ? extends Object> m) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("(g) 真实流 FlowScriptBindings(entrySet/putAll 抛 UOE)下仍可求值——仅用 get/containsKey")
|
||||
void flowScriptBindingsLike_noEntrySet() throws Exception {
|
||||
// 回归:B1 原 resolveBindings 用 putAll 合并 → 触 FlowScriptBindings.entrySet UOE,
|
||||
// 致所有带 conditionExpression 的 EL 写流崩(QA dogfooding 实证)。修后只走 get/containsKey。
|
||||
FlowScriptBindingsLike b = new FlowScriptBindingsLike();
|
||||
b.put("x", 5);
|
||||
b.put("isSave", Boolean.TRUE);
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("juel");
|
||||
assertNotNull(engine);
|
||||
assertEquals(6, ((Number) engine.eval("${x + 1}", b)).intValue());
|
||||
assertEquals(Boolean.TRUE, engine.eval("${isSave}", b)); // ${isSave} 转移条件:真实写流核心
|
||||
assertEquals(Boolean.TRUE, engine.eval("${x > 3}", b));
|
||||
assertNull(engine.eval("${nope}", b)); // 未绑定 → null,不抛、不触 entrySet
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user