apache/beam · error · IllegalStateException

The other object should be an instance of CEPLiteral

Error message

The other object should be an instance of CEPLiteral

What it means

In Apache Beam SQL's CEP (complex event processing) support, the inner CEPLiteral class for Byte values implements Comparable and requires that any object it is compared with is also a CEPLiteral. If compareTo is called with a foreign object (e.g. a raw Byte or null), the library throws this IllegalStateException instead of returning an ordering result. It is an internal contract check: CEPLiteral comparisons are only ever expected between literal instances produced by the CEP parser.

Source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java:75

      case CHAR:
      case VARCHAR:
        return of(lit.getValueAs(String.class));
      default:
        throw new SqlConversionException("SQL type not supported: " + lit.getTypeName().toString());
    }
  }

  public static CEPLiteral of(Byte myByte) {
    return new CEPLiteral(Schema.TypeName.BYTE) {
      @Override
      public Byte getByte() {
        return myByte;
      }

      @Override
      public int compareTo(Object other) {
        if (!(other instanceof CEPLiteral)) {
          throw new IllegalStateException("The other object should be an instance of CEPLiteral");
        }
        CEPLiteral otherLit = (CEPLiteral) other;
        if (getTypeName() != otherLit.getTypeName()) {
          throw new IllegalStateException(
              "The other CEPLiteral should have type "
                  + getTypeName().toString()
                  + ", given: "
                  + otherLit.getTypeName().toString());
        }
        return myByte.compareTo(otherLit.getByte());
      }
    };
  }

  public static CEPLiteral of(Short myShort) {
    return new CEPLiteral(Schema.TypeName.INT16) {
      @Override
      public Short getInt16() {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure the object passed to compareTo/equals is a CEPLiteral, not a raw boxed value
  2. Unwrap the other value's literal via its own CEPLiteral wrapper before comparing
  3. If comparing raw values, extract both sides' underlying values (e.g. getByte()) and compare those instead of the wrappers
  4. Wrap the raw value in a CEPLiteral of the same type before calling compareTo

Example fix

// before
boolean eq = byteLiteral.equals(myByte);
// after
boolean eq = byteLiteral.equals(CEPLiteral.of(myByte));
Defensive patterns

Strategy: type-guard

Validate before calling

// before comparing
if (other == null || !(other instanceof CEPLiteral)) {
  throw new IllegalArgumentException("expected CEPLiteral, got: " + other);
}

Type guard

static boolean isCepLiteral(Object o) {
  return o instanceof CEPLiteral;
}

Try / catch

try {
  int cmp = byteLiteral.compareTo(other);
} catch (IllegalStateException e) {
  // fall back to value-based comparison or log the contract violation
}

Prevention

When it happens

Trigger: Calling compareTo (directly or via equals, or via evalCondition during pattern matching) on a Byte-typed CEPLiteral passing anything that is not a CEPLiteral instance — e.g. new CEPLiteral(...).equals(rawByte), sorting a mixed collection containing CEPLiteral and native values, or a custom Condition/eval path feeding non-literal operands.

Common situations: Custom SQL CEP extensions or user code that unwraps CEPLiteral values before comparing; writing unit tests comparing CEPLiteral against plain java.lang.Byte; refactoring evalCondition to pass parsed row values instead of literal objects.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/6d4d71655c93efec. Report an issue: GitHub.