apache/skywalking · error · IllegalStateException
Failed to compile MAL expression for metric: {}, expression:
Error message
Failed to compile MAL expression for metric: {}, expression: {} What it means
Wrapper exception from DSL.parse(metricName, expression, ...): it compiles the expression through the MALClassGenerator (Javassist bytecode generation), and any Exception in the pipeline — ANTLR parsing, metadata validation, extension lookup, argument type checks, or Javassist compile — is rethrown as IllegalStateException naming the metric and the full expression. This is the primary user-facing failure when a MAL rule cannot be compiled at OAP startup.
Source
Thrown at oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/DSL.java:119
if (pool != null && targetClassLoader != null) {
// Per-file generator: one instance per compile is fine — it's just a thin
// orchestrator over ClassPool. Prevents cross-contamination of classNameHint /
// sourceRef state that the shared GENERATOR carries between calls.
final MALClassGenerator perFile = new MALClassGenerator(pool, targetClassLoader);
perFile.setSourceRef(sourceRef);
// The verbatim MAL expression text is the rule's "content" — threaded
// into the GateHolder so dsl-debugging records carry the rule source
// inline. Same string ANTLR parsed; no extra plumbing.
perFile.setContent(expression);
malExpr = perFile.compile(metricName, expression);
} else {
GENERATOR.setSourceRef(sourceRef);
GENERATOR.setContent(expression);
malExpr = GENERATOR.compile(metricName, expression);
}
return new Expression(metricName, expression, malExpr);
} catch (Exception e) {
throw new IllegalStateException(
"Failed to compile MAL expression for metric: " + metricName
+ ", expression: " + expression, e);
}
}
}
View on GitHub (pinned to 102af09b4a)
Solutions
- Inspect e.getCause() — the real error and its message (one of the specific compiler errors) determines the fix
- Fix the underlying issue in the rule YAML (syntax, quoting, scope, extension name/arity) and restart OAP
- For Javassist-level failures, set SW_DYNAMIC_CLASS_ENGINE_DEBUG=true to dump the generated .java/.class and compare with what the compiler produced
- Validate rules in a unit test using DSL.parse before deploying, so errors surface in CI rather than at OAP boot
Example fix
// before
Expression e = DSL.parse(metricName, expression, sourceRef, pool, loader);
// after
Expression e;
try {
e = DSL.parse(metricName, expression, sourceRef, pool, loader);
} catch (IllegalStateException ex) {
log.error("MAL rule '{}' failed to compile: {}", metricName, ex.getCause().getMessage(), ex);
throw ex;
} Defensive patterns
Strategy: try-catch
Validate before calling
try {
DSL.parse(metricName, expression, sourceRef, pool, targetClassLoader);
} catch (IllegalStateException e) {
throw new AssertionError("Rule '" + metricName + "' invalid: " + e.getMessage(), e);
} Try / catch
catch IllegalStateException around each DSL.parse during rule loading; log metricName + expression + e.getCause(), and abort startup so a half-registered rule set cannot run
Prevention
- Compile all custom MAL rules in CI with DSL.parse before deploying OAP
- Set SW_DYNAMIC_CLASS_ENGINE_DEBUG=true when diagnosing codegen-stage failures to inspect generated .java
- After OAP upgrades, run the shipped rule comparison tests to catch grammar/behavior drift
When it happens
Trigger: DSL.parse invoked per rule during analyzer init; throws when the combined expression (expPrefix+exp+expSuffix) trips any earlier error in this catalog (49-51 parse, 42-48 extension, 40-41 decorate, 52-57 already thrown at registry init) or when Javassist rejects the generated source.
Common situations: Any malformed custom MAL rule file dropped into meter-analyzer-config / otel-rules / telegraf / zabbix / envoy rule directories; upgrading OAP to the v2 engine where previously-tolerated v1 expressions now fail; classpath issues with extension jars.
Related errors
- decorate() should be invoked after service()
- Failed to parse MAL expression for metadata: {}
- Some configuration files of enabled rules are not found, ena
- Load meter analyzer configs failed
- {slot} value '{numText}' exceeds the supported range (must f
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/ab496a105f9a775e.
Report an issue: GitHub.