xai-org/x-algorithm · error · IllegalArgumentException
Invalid numeric type (%s)
Error message
Invalid numeric type (%s)
What it means
Abs.apply throws IllegalArgumentException when the argument is a Number that is neither doubleLike nor longLike per the Type classifier. The Abs function only accepts numeric types it recognizes (double/float-like or long/int-like); anything else (e.g. BigDecimal, exotic Number subclasses) is rejected.
Source
Thrown at botmaker/src/java/com/twitter/botmaker/function/math/Abs.java:53
public Signature getSignature() {
return SIGNATURE;
}
@Override
protected CacheLevel getCacheLevel() {
return CacheLevel.Global;
}
@Override
public Object apply(Context<Runtime> context, Number num) {
if (Type.doubleLike(num)) {
return Math.abs(num.doubleValue());
} else if (Type.longLike(num)) {
return Math.abs(num.longValue());
}
throw new IllegalArgumentException(String.format("Invalid numeric type (%s)", num));
}
}
View on GitHub (pinned to 24c60942c5)
Solutions
- Convert the value to a Double or Long before passing it to Abs() (e.g. wrap with a ToDouble/ToLong conversion function in the expression)
- Ensure the upstream function's declared return Type is a recognized numeric type (DoubleType/LongType etc.)
- As a library maintainer, add BigDecimal handling or a clear numeric-type whitelist
Example fix
// before
Abs().apply(ctx, new BigDecimal("-5")) // -> IllegalArgumentException
// after
Abs().apply(ctx, -5.0) // Double is doubleLike
Defensive patterns
Strategy: validation
Validate before calling
boolean isSupportedNumber(Number n) {
return Type.doubleLike(n) || Type.longLike(n);
}
// call before Abs().apply(ctx, num) Type guard
public static boolean absApplicable(Object v) {
return v instanceof Number && (Type.doubleLike((Number) v) || Type.longLike((Number) v));
} Prevention
- Standardize numeric values to Double/Long at data-ingestion boundaries
- Avoid BigDecimal/custom Number subclasses in botmaker expressions
- Add unit tests covering numeric type variants for math functions
When it happens
Trigger: Calling Abs() on a value whose runtime Number implementation is not classified as doubleLike or longLike by com.twitter.botmaker Type helpers, e.g. passing a BigDecimal or a custom Number subclass through the expression engine.
Common situations: Expressions built over data sources that produce BigDecimal/BigInteger (e.g. decimal columns from a database or JSON parser), or custom Number subclasses registered as botmaker return types.
Related errors
- function passed to Foldl() returns %s but seed value is a %s
- Foldl1 is expected to return %s but passed function returns
- Sort is expected to return %s but passed function returns %s
- Parameter #%d of %s should be %s, received %s instead
- %s cannnot be converted to %s. missing field %s.
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/4201a75e28cdccd6.
Report an issue: GitHub.