{"record":{"id":"4ff61772628c820f","repo":"apache/beam","slug":"the-class-must-be-subclassed-properly-to-use-this-method","errorCode":null,"errorMessage":"the class must be subclassed properly to use this method","messagePattern":"the class must be subclassed properly to use this method","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java","lineNumber":316,"sourceCode":"      public int compareTo(Object other) {\n        if (!(other instanceof CEPLiteral)) {\n          throw new IllegalStateException(\"The other object should be an instance of CEPLiteral\");\n        }\n        CEPLiteral otherLit = (CEPLiteral) other;\n        if (getTypeName() != otherLit.getTypeName()) {\n          throw new IllegalStateException(\n              \"The other CEPLiteral should have type \"\n                  + getTypeName().toString()\n                  + \", given: \"\n                  + otherLit.getTypeName().toString());\n        }\n        return myString.compareTo(otherLit.getString());\n      }\n    };\n  }\n\n  public int compareTo(Object other) {\n    throw new IllegalStateException(\"the class must be subclassed properly to use this method\");\n  }\n  ;\n\n  @Override\n  public boolean equals(Object other) {\n    if (!(other instanceof CEPLiteral)) {\n      throw new IllegalStateException(\"The other object should be an instance of CEPLiteral\");\n    }\n    return this.compareTo(other) == 0;\n  }\n\n  @Override\n  public int hashCode() {\n    return typeName.hashCode();\n  }\n\n  public Byte getByte() {\n    throw new IllegalStateException(\"the class must be subclassed properly to get the value\");","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java#L298-L334","documentation":"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.","triggerScenarios":"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.","commonSituations":"Test stubs subclassing CEPLiteral without overriding compareTo; custom extensions building their own CEPLiteral subtypes; deserialization or factory code bypassing CEPLiteral.of.","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."],"exampleFix":"// before\nCEPLiteral lit = new CEPLiteral(Schema.TypeName.INT32) { public Integer getInt32() { return 1; } }; // compareTo not overridden\n// after\nCEPLiteral lit = CEPLiteral.of(1);","handlingStrategy":"validation","validationCode":"// java\nif (literal.getClass().isAnonymousClass() || literal.getTypeName() != null) {\n  // prefer factory construction\n  CEPLiteral safe = CEPLiteral.of(literal.getString());\n}","typeGuard":null,"tryCatchPattern":"// java\ntry {\n  literal.compareTo(other);\n} catch (IllegalStateException e) {\n  // instance was not created via CEPLiteral.of; rebuild it\n}","preventionTips":["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."],"tags":["cep","abstract-method","subclassing","beam-sql"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}