{"record":{"id":"66ccb3528673d249","repo":"alibaba/COLA","slug":"execute-not-supported-for-or-relation-composite","errorCode":null,"errorMessage":"execute not supported for OR relation composite","messagePattern":"execute not supported for OR relation composite","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-ruleengine/src/main/java/com/alibaba/cola/ruleengine/core/AnyRules.java","lineNumber":26,"sourceCode":"public class AnyRules extends CompositeRule{\n\n    public static CompositeRule anyOf(Rule... rules) {\n        CompositeRule instance = new AnyRules();\n        Collections.addAll(instance.rules, rules);\n        return instance;\n    }\n\n    @Override\n    public boolean evaluate(Facts facts) {\n        if (rules.stream().anyMatch(rule -> rule.evaluate(facts)))\n            return true;\n        return false;\n    }\n\n    @Override\n    public void execute(Facts facts) {\n        //不支持OR relation\n        throw new RuntimeException(\"execute not supported for OR relation composite\");\n    }\n\n    @Override\n    protected boolean doApply(Facts facts) {\n        for (Rule rule : rules) {\n            //短路操作，只要第一个rule成功执行，其它就不执行了\n            if (rule.apply(facts)) {\n                return true;\n            }\n        }\n        return false;\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":40,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-ruleengine/src/main/java/com/alibaba/cola/ruleengine/core/AnyRules.java#L8-L40","documentation":"AnyRules is an OR-composite rule in the COLA rule engine: it evaluates children with short-circuit OR semantics but does not support executing actions. Calling execute() directly on an AnyRules composite is intentionally unsupported, so it unconditionally throws this RuntimeException. Composition rules should only be used to drive evaluation of their children, not to execute facts themselves.","triggerScenarios":"Calling rule.execute(facts) on a rule built via AnyRules.or(...) instead of calling execute on a leaf/child rule, or calling execute on a composite parent rather than letting doApply/evaluate drive child execution.","commonSituations":"Developers build an OR composite rule and then treat it like a normal rule, invoking execute() in a rules engine runner loop; confusion over the Rule interface's execute contract applying to composites.","solutions":["Do not call execute() on AnyRules composites; execute only leaf rules (e.g. SimpleRules/LightRules) or iterate rules returned by the composite","Use evaluate(facts) on the AnyRules composite to get OR short-circuit evaluation of children, then execute child rules that return true","Restructure the rule tree so composites only contain conditional logic and actions live in leaf rules"],"exampleFix":"// before\nAnyRules<Integer, MyContext> orRule = AnyRules.or(ruleA, ruleB);\norRule.execute(facts); // throws\n\n// after\nif (orRule.evaluate(facts)) {\n    matchedRule.execute(facts);\n}","handlingStrategy":"try-catch","validationCode":"if (rule instanceof AnyRules) {\n    boolean matched = rule.evaluate(facts);\n    // execute only leaf rules that matched\n}","typeGuard":"boolean isExecutableRule(Object rule) {\n    return rule != null && !(rule instanceof AnyRules);\n}","tryCatchPattern":"try {\n    composite.execute(facts);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"execute not supported for OR relation\")) {\n        // fall back to evaluate + child execution\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never call execute() on AnyRules composites","Keep actions in leaf rules only","Use evaluate() to drive OR composition logic"],"tags":["ruleengine","unsupported-operation","composite-rule"],"backgroundTag":"unsupported-operation","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}