{"record":{"id":"386321f48cf8bdd3","repo":"alibaba/COLA","slug":"evaluate-not-supported-for-natural-composite","errorCode":null,"errorMessage":"evaluate not supported for natural composite","messagePattern":"evaluate 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":25,"sourceCode":"\nimport java.util.Collections;\n\n/**\n * This is Natural Rules\n */\npublic 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":7,"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#L7-L43","documentation":"NaturalRules is a sequential composite ('natural' rule group) that executes its children in order but cannot itself be evaluated as part of a parent rule tree. Its evaluate() method is deliberately unsupported because natural composites are top-level rule containers, not composable condition nodes. Calling evaluate() on NaturalRules always throws this RuntimeException.","triggerScenarios":"Calling evaluate(facts) on a NaturalRules instance, or nesting a NaturalRules as a child inside another composite rule (AND/OR) whose parent then calls evaluate on it.","commonSituations":"Developers nest NaturalRules inside AnyRules/AllRules for composition; a generic rule runner that calls evaluate() on every rule in a list hits the natural composite.","solutions":["Do not nest NaturalRules inside other composite rules; keep it as the top-level rule","Use AllRules.and(...) or AnyRules.or(...) if you need an evaluatable composite, and execute children individually","In generic runners, check the rule type and call execute() for NaturalRules instead of evaluate()"],"exampleFix":"// before\nAllRules.and(naturalRule, otherRule); // parent evaluate() -> throws\n\n// after\nNaturalRules top = NaturalRules.natural(ruleA, ruleB); // top-level only\ntop.execute(facts);","handlingStrategy":"type-guard","validationCode":"if (rule instanceof NaturalRules) {\n    throw new IllegalArgumentException(\"NaturalRules cannot be nested as a child rule\");\n}","typeGuard":"boolean isEvaluatable(Object rule) {\n    return rule != null && !(rule instanceof NaturalRules);\n}","tryCatchPattern":"try {\n    return rule.evaluate(facts);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"evaluate not supported for natural composite\")) {\n        return false; // or route to execute-based handling\n    }\n    throw e;\n}","preventionTips":["Keep NaturalRules top-level only","Never nest NaturalRules inside AllRules/AnyRules","In generic runners, branch on rule type before calling evaluate"],"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"}