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

  1. 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)
  2. Ensure the upstream function's declared return Type is a recognized numeric type (DoubleType/LongType etc.)
  3. 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

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


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/4201a75e28cdccd6. Report an issue: GitHub.