{"record":{"id":"55d9e2a5f6298304","repo":"apache/beam","slug":"the-class-must-be-subclassed-properly-to-get-the-value","errorCode":null,"errorMessage":"the class must be subclassed properly to get the value","messagePattern":"the class must be subclassed properly to get the value","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":334,"sourceCode":"    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\");\n  }\n\n  public Short getInt16() {\n    throw new IllegalStateException(\"the class must be subclassed properly to get the value\");\n  }\n\n  public Integer getInt32() {\n    throw new IllegalStateException(\"the class must be subclassed properly to get the value\");\n  }\n\n  public Long getInt64() {\n    throw new IllegalStateException(\"the class must be subclassed properly to get the value\");\n  }\n\n  public BigDecimal getDecimal() {\n    throw new IllegalStateException(\"the class must be subclassed properly to get the value\");\n  }\n","sourceCodeStart":316,"sourceCodeEnd":352,"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#L316-L352","documentation":"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.","triggerScenarios":"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).","commonSituations":"Generic code iterating CEPOperations and calling getByte() without checking getTypeName() == Schema.TypeName.BYTE first; type-erased extraction of literal values in custom CEP utilities.","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."],"exampleFix":"// before\nByte b = lit.getByte(); // IllegalStateException if lit is INT32\n// after\nByte b = lit.getTypeName() == Schema.TypeName.BYTE ? lit.getByte() : null;","handlingStrategy":"validation","validationCode":"// java\nif (lit.getTypeName() == Schema.TypeName.BYTE) {\n  Byte b = lit.getByte();\n}","typeGuard":"// java\nstatic boolean isByteLiteral(CEPOperation op) {\n  return op instanceof CEPLiteral && ((CEPLiteral) op).getTypeName() == Schema.TypeName.BYTE;\n}","tryCatchPattern":"// java\ntry {\n  Byte b = lit.getByte();\n} catch (IllegalStateException e) {\n  // literal is not BYTE-typed; dispatch on getTypeName()\n}","preventionTips":["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)."],"tags":["cep","type-mismatch","accessor","beam-sql"],"backgroundTag":"type-mismatch","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"}