apache/beam · error · IllegalStateException
the class must be subclassed properly to get the value
Error message
the class must be subclassed properly to get the value
What it means
Base CEPLiteral.getByte() unconditionally throws this IllegalStateException. Concrete value accessors are only implemented on the anonymous subclasses created by CEPLiteral.of(Byte); calling getByte() on a literal of a different type (or a non-factory instance) fails because there is no byte value to return. This enforces that callers only extract the value matching the literal's Schema.TypeName.
Solutions
- Check lit.getTypeName() == Schema.TypeName.BYTE before calling getByte().
- Route extraction through a switch on getTypeName() calling the matching get* method.
- Create literals with CEPLiteral.of(Byte) if a byte value is expected.
Example fix
// before Byte b = lit.getByte(); // IllegalStateException if lit is INT32 // after Byte b = lit.getTypeName() == Schema.TypeName.BYTE ? lit.getByte() : null;
Defensive patterns
Strategy: validation
Validate before calling
// java
if (lit.getTypeName() == Schema.TypeName.BYTE) {
Byte b = lit.getByte();
} Type guard
// java
static boolean isByteLiteral(CEPOperation op) {
return op instanceof CEPLiteral && ((CEPLiteral) op).getTypeName() == Schema.TypeName.BYTE;
} Try / catch
// java
try {
Byte b = lit.getByte();
} catch (IllegalStateException e) {
// literal is not BYTE-typed; dispatch on getTypeName()
} Prevention
- Dispatch value extraction through a switch on getTypeName().
- Never assume a literal's type; always check before calling a get* accessor.
- Create byte literals only via CEPLiteral.of(Byte).
When it happens
Trigger: Calling getByte() on a CEPLiteral created by CEPLiteral.of with any other overload (Integer, String, Boolean, ...) or on a base-class instance not built via CEPLiteral.of(Byte).
Common situations: Generic code iterating CEPOperations and calling getByte() without checking getTypeName() == Schema.TypeName.BYTE first; type-erased extraction of literal values in custom CEP utilities.
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
- key field type should be STRING but was
- Only INT64 is supported as the interval value for BigQuery.
- Predicate node ' ' should be a boolean expression, but was
- RexNode not supported:
- SQL type not supported:
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/55d9e2a5f6298304.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java:334
throw new IllegalStateException("the class must be subclassed properly to use this method");
}
;
@Override
public boolean equals(Object other) {
if (!(other instanceof CEPLiteral)) {
throw new IllegalStateException("The other object should be an instance of CEPLiteral");
}
return this.compareTo(other) == 0;
}
@Override
public int hashCode() {
return typeName.hashCode();
}
public Byte getByte() {
throw new IllegalStateException("the class must be subclassed properly to get the value");
}
public Short getInt16() {
throw new IllegalStateException("the class must be subclassed properly to get the value");
}
public Integer getInt32() {
throw new IllegalStateException("the class must be subclassed properly to get the value");
}
public Long getInt64() {
throw new IllegalStateException("the class must be subclassed properly to get the value");
}
public BigDecimal getDecimal() {
throw new IllegalStateException("the class must be subclassed properly to get the value");
}
View on GitHub (pinned to 12126d8942)