{"record":{"id":"6d4d71655c93efec","repo":"apache/beam","slug":"the-other-object-should-be-an-instance-of-cepliteral","errorCode":null,"errorMessage":"The other object should be an instance of CEPLiteral","messagePattern":"The other object should be an instance of CEPLiteral","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":75,"sourceCode":"      case CHAR:\n      case VARCHAR:\n        return of(lit.getValueAs(String.class));\n      default:\n        throw new SqlConversionException(\"SQL type not supported: \" + lit.getTypeName().toString());\n    }\n  }\n\n  public static CEPLiteral of(Byte myByte) {\n    return new CEPLiteral(Schema.TypeName.BYTE) {\n      @Override\n      public Byte getByte() {\n        return myByte;\n      }\n\n      @Override\n      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 myByte.compareTo(otherLit.getByte());\n      }\n    };\n  }\n\n  public static CEPLiteral of(Short myShort) {\n    return new CEPLiteral(Schema.TypeName.INT16) {\n      @Override\n      public Short getInt16() {","sourceCodeStart":57,"sourceCodeEnd":93,"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#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the object passed to compareTo/equals is a CEPLiteral, not a raw boxed value","Unwrap the other value's literal via its own CEPLiteral wrapper before comparing","If comparing raw values, extract both sides' underlying values (e.g. getByte()) and compare those instead of the wrappers","Wrap the raw value in a CEPLiteral of the same type before calling compareTo"],"exampleFix":"// before\nboolean eq = byteLiteral.equals(myByte);\n// after\nboolean eq = byteLiteral.equals(CEPLiteral.of(myByte));","handlingStrategy":"type-guard","validationCode":"// before comparing\nif (other == null || !(other instanceof CEPLiteral)) {\n  throw new IllegalArgumentException(\"expected CEPLiteral, got: \" + other);\n}","typeGuard":"static boolean isCepLiteral(Object o) {\n  return o instanceof CEPLiteral;\n}","tryCatchPattern":"try {\n  int cmp = byteLiteral.compareTo(other);\n} catch (IllegalStateException e) {\n  // fall back to value-based comparison or log the contract violation\n}","preventionTips":["Always construct comparisons from CEPLiteral instances produced by the CEP parser","Never mix raw boxed values with CEPLiteral in collections sorted or compared as one type","When overriding condition evaluation, wrap operands with the matching CEPLiteral factory","In tests, assert on CEPLiteral.equals(CEPLiteral) or compare extracted values"],"tags":["java","cep","sql","comparable","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}