apache/skywalking · error · IllegalArgumentException
castType:{castType} is legal, context expression:{originalEx
Error message
castType:{castType} is legal, context expression:{originalExpression} What it means
TypeCastUtil.withCast wraps an OAL attribute expression with a Java cast call during code generation. Only '(str->long)', '(long)', '(str->int)' and '(int)' are recognized; anything else hits default and throws. (Note the message text says 'is legal' but it means 'is illegal' — a long-standing wording quirk.)
Source
Thrown at oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/util/TypeCastUtil.java:39
public class TypeCastUtil {
/**
* @param castType to change the value of given original expression.
* @param originalExpression to read the value
* @return cast expression if cast type exists and is legal.
*/
public static String withCast(String castType, String originalExpression) {
if (castType == null) {
return originalExpression;
}
switch (castType) {
case "(str->long)":
case "(long)":
return "Long.parseLong(" + originalExpression + ")";
case "(str->int)":
case "(int)":
return "Integer.parseInt(" + originalExpression + ")";
default:
throw new IllegalArgumentException(
"castType:" + castType + " is legal, context expression:" + originalExpression);
}
}
}
View on GitHub (pinned to 102af09b4a)
Solutions
- Use only the supported casts: (str->long) / (long) and (str->int) / (int)
- If a double/boolean conversion is needed, preprocess the value upstream (e.g. in MAL/LAL or the agent) so the OAL source attribute is already numeric
- Remove the cast entirely if the attribute is already the right type
Example fix
// before (OAL)
latency = from Span.tag('lat')(str->double).avg() --> latencyAvg
// after
latency = from Span.tag('lat')(str->long).avg() --> latencyAvg Defensive patterns
Strategy: validation
Validate before calling
// Lint OAL casts before deploy:
Set<String> ok = Set.of("(str->long)", "(long)", "(str->int)", "(int)");
for (String cast : castsUsed(script)) {
if (!ok.contains(cast)) throw new ConfigException("Unsupported OAL cast: " + cast);
} Try / catch
In OAL validation tooling, catch IllegalArgumentException from the enricher and surface it with the rule's file:line; do not catch in OAP startup.
Prevention
- Remember OAL casts only convert strings to long/int — never double, boolean, or reverse
- Read the message knowing 'is legal' actually means 'is illegal' (wording quirk) — the castType and expression in it are accurate
When it happens
Trigger: An OAL expression uses an unsupported cast such as (str->double), (str->boolean), or a typo like (string->long). The grammar may accept the cast token but the code generator has no lowering for it.
Common situations: Trying to cast a string metric attribute to a type other than long/int (e.g. building a double metric from a tag); typo in the cast syntax; assuming SQL-style CAST semantics in OAL.
Related errors
- filter expression [{}] not found
- Can't find metrics, {}
- Unknown filter value type: {}
- Unsupported number operator: {}
- Unsupported string operator: {}
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/70da16a71855c109.
Report an issue: GitHub.