{"record":{"id":"951d58ee09d332ca","repo":"alibaba/COLA","slug":"execute-not-supported-for-natural-composite","errorCode":null,"errorMessage":"execute not supported for natural composite","messagePattern":"execute not supported for natural composite","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-ruleengine/src/main/java/com/alibaba/cola/ruleengine/core/NaturalRules.java","lineNumber":31,"sourceCode":"public class NaturalRules extends CompositeRule{\n    private static final Logger LOGGER = LoggerFactory.getLogger(NaturalRules.class);\n\n    public static CompositeRule of(Rule... rules) {\n        CompositeRule instance = new NaturalRules();\n        Collections.addAll(instance.rules, rules);\n        return instance;\n    }\n\n    @Override\n    public boolean evaluate(Facts facts) {\n        //不支持, which means Natural Rules can not be the children of other rules\n        throw new RuntimeException(\"evaluate not supported for natural composite\");\n    }\n\n    @Override\n    public void execute(Facts facts) {\n        //不支持, which means Natural Rules can not be the children of other rules\n        throw new RuntimeException(\"execute not supported for natural composite\");\n    }\n\n    @Override\n    protected boolean doApply(Facts facts) {\n        LOGGER.debug(\"start Natural composite rule apply\");\n        for (Rule rule : rules) {\n            rule.apply(facts);\n        }\n        return true;\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":43,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-ruleengine/src/main/java/com/alibaba/cola/ruleengine/core/NaturalRules.java#L13-L43","documentation":"NaturalRules is a sequential composite that cannot itself execute facts directly the way a parent composite does; its execute() is intentionally unsupported because it is meant to be the top-level group whose children are driven via doApply, not invoked as an actionable rule. Calling execute() on NaturalRules always throws this RuntimeException.","triggerScenarios":"Calling execute(facts) directly on a NaturalRules instance, or a rule runner invoking execute() on every rule including natural composites.","commonSituations":"Generic engines/loops that uniformly call execute() on all rules; developers assuming all Rule implementations support execute.","solutions":["Do not call execute() on NaturalRules directly; register it as a top-level rule group and let child rules execute via doApply","Use AllRules.and(...) or AnyRules.or(...) for a composite that supports execute() semantics, and keep actions in leaf rules","In runners, branch on rule type and skip execute() for NaturalRules"],"exampleFix":"// before\nNaturalRules group = NaturalRules.natural(ruleA, ruleB);\ngroup.execute(facts); // throws\n\n// after\nAllRules.and(ruleA, ruleB).execute(facts); // execut-able composite","handlingStrategy":"type-guard","validationCode":"if (rule instanceof NaturalRules) {\n    // skip execute; drive children through the natural group's own apply path\n}","typeGuard":"boolean supportsExecute(Object rule) {\n    return rule != null && !(rule instanceof NaturalRules);\n}","tryCatchPattern":"try {\n    group.execute(facts);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"execute not supported for natural composite\")) {\n        // use an execut-able composite (AllRules) or leaf rules instead\n    } else {\n        throw e;\n    }\n}","preventionTips":["Do not invoke execute() on NaturalRules","Use AllRules.and(...) when you need an executable composite","Register NaturalRules as a top-level rule group only"],"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"}