{"record":{"id":"5b9cdab793894a52","repo":"redis/jedis","slug":"payload-must-be-string-or-byte","errorCode":null,"errorMessage":"payload must be String or byte[]","messagePattern":"payload must be String or byte\\[\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/CompareCondition.java","lineNumber":52,"sourceCode":"\n    private final Keyword keyword;\n\n    Condition(Keyword keyword) {\n      this.keyword = keyword;\n    }\n\n    /** The protocol keyword to emit for this condition. */\n    public Keyword getKeyword() {\n      return keyword;\n    }\n  }\n\n  private final Condition condition;\n  private final Object payload; // String or byte[]\n\n  private CompareCondition(Condition condition, Object payload) {\n    if (!(payload instanceof String) && !(payload instanceof byte[])) {\n      throw new IllegalArgumentException(\"payload must be String or byte[]\");\n    }\n    this.condition = condition;\n    this.payload = payload;\n  }\n\n  // Factory methods: value-based\n  public static CompareCondition valueEq(String value) {\n    JedisAsserts.notNull(value, \"value must not be null\");\n    return new CompareCondition(Condition.VALUE_EQUAL, value);\n  }\n\n  public static CompareCondition valueNe(String value) {\n    JedisAsserts.notNull(value, \"value must not be null\");\n    return new CompareCondition(Condition.VALUE_NOT_EQUAL, value);\n  }\n\n  public static CompareCondition valueEq(byte[] value) {\n    JedisAsserts.notNull(value, \"value must not be null\");","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/CompareCondition.java#L34-L70","documentation":"CompareCondition's private constructor validates that its payload is either a String or a byte[]; anything else triggers this IllegalArgumentException. The library only knows how to encode those two payload types for compare conditions, so other object types are rejected at construction time.","triggerScenarios":"Calling a CompareCondition factory or constructor with a payload that is neither String nor byte[], e.g. an Integer, Long, Double, byte-buffer wrapper, or a custom object.","commonSituations":"Passing numeric values boxed as Integer/Long instead of converting to String; passing a ByteBuffer instead of byte[]; generic code that forwards Object payloads without knowing the accepted types.","solutions":["Convert the payload to a String (e.g. String.valueOf(value)) before passing it","Or convert to byte[] (use SafeEncoder.encode or Protocol.toByteArray for numbers)","Add a type check at the call site to fail fast with a clearer message"],"exampleFix":"// before\nCompareCondition cond = CompareCondition.equals(42);\n// after\nCompareCondition cond = CompareCondition.equals(String.valueOf(42));","handlingStrategy":"type-guard","validationCode":"if (!(payload instanceof String) && !(payload instanceof byte[])) { throw new IllegalArgumentException(\"payload must be String or byte[]\"); }","typeGuard":"boolean isValidPayload(Object p) { return p instanceof String || p instanceof byte[]; }","tryCatchPattern":"try {\n  CompareCondition c = CompareCondition.equals(value);\n} catch (IllegalArgumentException e) {\n  // convert value to String/byte[] and retry\n}","preventionTips":["Always pass String or byte[] payloads to compare conditions","Convert numbers with String.valueOf or Protocol.toByteArray","Validate payload type at your API boundary"],"tags":["java","illegal-argument","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}