apache/beam · error · IllegalStateException
the class must be subclassed properly to use this method
Error message
the class must be subclassed properly to use this method
What it means
The base CEPLiteral class provides a non-overridden compareTo() that unconditionally throws this IllegalStateException. Only the anonymous subclasses returned by CEPLiteral.of(...) override compareTo; calling it on an instance created by any other means (e.g. direct subclassing without overriding, or reflection) fails. It signals that the object was not constructed through the intended type-specific factory.
Solutions
- Always create CEPLiteral instances via the static CEPLiteral.of(...) factories.
- If subclassing, override compareTo() (and the matching get* accessor).
- In tests, use CEPLiteral.of with the same type as the production literal instead of hand-rolled subclasses.
Example fix
// before
CEPLiteral lit = new CEPLiteral(Schema.TypeName.INT32) { public Integer getInt32() { return 1; } }; // compareTo not overridden
// after
CEPLiteral lit = CEPLiteral.of(1); Defensive patterns
Strategy: validation
Validate before calling
// java
if (literal.getClass().isAnonymousClass() || literal.getTypeName() != null) {
// prefer factory construction
CEPLiteral safe = CEPLiteral.of(literal.getString());
} Try / catch
// java
try {
literal.compareTo(other);
} catch (IllegalStateException e) {
// instance was not created via CEPLiteral.of; rebuild it
} Prevention
- Always instantiate CEPLiteral through the static CEPLiteral.of(...) factories.
- If subclassing for tests, override compareTo() and the relevant get* accessor.
- Never construct CEPLiteral anonymous subclasses that skip compareTo.
When it happens
Trigger: Invoking compareTo()/equals() on a CEPLiteral instance that was not produced by one of the CEPLiteral.of(...) factories — e.g. an anonymous subclass that overrides a getter but not compareTo, or a test double created by subclassing CEPLiteral directly.
Common situations: Test stubs subclassing CEPLiteral without overriding compareTo; custom extensions building their own CEPLiteral subtypes; deserialization or factory code bypassing CEPLiteral.of.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- RexNode not supported:
- SQL type not supported:
- the class must be subclassed properly to get the value
- A 'datagen' table requires either 'rows-per-second' (for…
- ALTER is not supported for table
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/4ff61772628c820f.
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:316
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 myString.compareTo(otherLit.getString());
}
};
}
public int compareTo(Object other) {
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");View on GitHub (pinned to 12126d8942)