alibaba/COLA · error · RuntimeException

execute not supported for natural composite

Error message

execute not supported for natural composite

What it means

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.

Source

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

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 call execute() on NaturalRules directly; register it as a top-level rule group and let child rules execute via doApply
  2. Use AllRules.and(...) or AnyRules.or(...) for a composite that supports execute() semantics, and keep actions in leaf rules
  3. In runners, branch on rule type and skip execute() for NaturalRules

Example fix

// before
NaturalRules group = NaturalRules.natural(ruleA, ruleB);
group.execute(facts); // throws

// after
AllRules.and(ruleA, ruleB).execute(facts); // execut-able composite
Defensive patterns

Strategy: type-guard

Validate before calling

if (rule instanceof NaturalRules) {
    // skip execute; drive children through the natural group's own apply path
}

Type guard

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

Try / catch

try {
    group.execute(facts);
} catch (RuntimeException e) {
    if (e.getMessage().contains("execute not supported for natural composite")) {
        // use an execut-able composite (AllRules) or leaf rules instead
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling execute(facts) directly on a NaturalRules instance, or a rule runner invoking execute() on every rule including natural composites.

Common situations: Generic engines/loops that uniformly call execute() on all rules; developers assuming all Rule implementations support execute.

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/951d58ee09d332ca. Report an issue: GitHub.