alibaba/COLA · error · RuntimeException

evaluate not supported for natural composite

Error message

evaluate not supported for natural composite

What it means

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.

Source

Thrown at cola-components/cola-component-ruleengine/src/main/java/com/alibaba/cola/ruleengine/core/NaturalRules.java:25

import java.util.Collections;

/**
 * This is Natural Rules
 */
public class NaturalRules extends CompositeRule{
    private static final Logger LOGGER = LoggerFactory.getLogger(NaturalRules.class);

    public static CompositeRule of(Rule... rules) {
        CompositeRule instance = new NaturalRules();
        Collections.addAll(instance.rules, rules);
        return instance;
    }

    @Override
    public boolean evaluate(Facts facts) {
        //不支持, which means Natural Rules can not be the children of other rules
        throw new RuntimeException("evaluate not supported for natural composite");
    }

    @Override
    public void execute(Facts facts) {
        //不支持, which means Natural Rules can not be the children of other rules
        throw new RuntimeException("execute not supported for natural composite");
    }

    @Override
    protected boolean doApply(Facts facts) {
        LOGGER.debug("start Natural composite rule apply");
        for (Rule rule : rules) {
            rule.apply(facts);
        }
        return true;
    }
}

View on GitHub (pinned to 352e1a8675)

Solutions

  1. Do not nest NaturalRules inside other composite rules; keep it as the top-level rule
  2. Use AllRules.and(...) or AnyRules.or(...) if you need an evaluatable composite, and execute children individually
  3. In generic runners, check the rule type and call execute() for NaturalRules instead of evaluate()

Example fix

// before
AllRules.and(naturalRule, otherRule); // parent evaluate() -> throws

// after
NaturalRules top = NaturalRules.natural(ruleA, ruleB); // top-level only
top.execute(facts);
Defensive patterns

Strategy: type-guard

Validate before calling

if (rule instanceof NaturalRules) {
    throw new IllegalArgumentException("NaturalRules cannot be nested as a child rule");
}

Type guard

boolean isEvaluatable(Object rule) {
    return rule != null && !(rule instanceof NaturalRules);
}

Try / catch

try {
    return rule.evaluate(facts);
} catch (RuntimeException e) {
    if (e.getMessage().contains("evaluate not supported for natural composite")) {
        return false; // or route to execute-based handling
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of alibaba/COLA@352e1a8675 (2026-09-08). Data as JSON: /api/errors/386321f48cf8bdd3. Report an issue: GitHub.