{"record":{"id":"c7f87c3babdea743","repo":"redis/jedis","slug":"message-cannot-be-null","errorCode":null,"errorMessage":"Message cannot be null","messagePattern":"Message cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/PushConsumerContext.java","lineNumber":30,"sourceCode":" * Consumers can inspect the message and decide weather to :\n * <ul>\n * <li>return to the caller and skip the rest of consumers by calling\n * {@link PushConsumerContext#propagate()}</li>\n * <li>drop message without processing it further by calling {@link PushConsumerContext#drop()}\n * to</li>\n * <li>inspect and let it be processed by following consumers</li>\n * </ul>\n */\n@Experimental\npublic class PushConsumerContext {\n  private final PushMessage message;\n\n  private boolean propagate = false;\n  private boolean drop = false;\n\n  public PushConsumerContext(PushMessage message) {\n    if (message == null) {\n      throw new IllegalArgumentException(\"Message cannot be null\");\n    }\n    this.message = message;\n  }\n\n  /**\n   * Get the push message being processed.\n   * @return The push message\n   */\n  public PushMessage getMessage() {\n    return message;\n  }\n\n  /**\n   * Check if the message should be returned to the caller.\n   * @return true if the message should be returned to the caller\n   */\n  public boolean shouldPropagate() {\n    return propagate;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/PushConsumerContext.java#L12-L48","documentation":"PushConsumerContext wraps a PushMessage being processed in the push-mode (client-side push notifications) consumer. The constructor validates its single argument and throws IllegalArgumentException immediately if it is null, because a context without a message has no meaning and would fail later with a confusing NPE. This is a fast-fail contract check in the library's public constructor.","triggerScenarios":"Calling new PushConsumerContext(null) directly, or passing a variable holding null (e.g. a message obtained from a queue/lookup that returned null) into the constructor instead of the required PushMessage instance.","commonSituations":"Tests constructing contexts manually; helper code that extracts a PushMessage from a registry or map (null when absent) and forwards it without checking; refactoring that changed a message-returning method to return null on miss.","solutions":["Ensure the PushMessage passed to the constructor is non-null before constructing the context.","If the message comes from a lookup, check for null and handle the 'no message' case instead of building a context.","Catch IllegalArgumentException at the call site as a last-resort guard in generic dispatch code."],"exampleFix":"// before\nPushMessage msg = pending.get(id);\nPushConsumerContext ctx = new PushConsumerContext(msg);\n\n// after\nPushMessage msg = pending.get(id);\nif (msg == null) {\n  throw new IllegalStateException(\"No push message pending for id \" + id);\n}\nPushConsumerContext ctx = new PushConsumerContext(msg);","handlingStrategy":"validation","validationCode":"if (message == null) {\n  throw new IllegalStateException(\"PushMessage must be resolved before building PushConsumerContext\");\n}\nPushConsumerContext ctx = new PushConsumerContext(message);","typeGuard":"boolean hasMessage(PushMessage m) { return m != null; }","tryCatchPattern":"try {\n  PushConsumerContext ctx = new PushConsumerContext(message);\n} catch (IllegalArgumentException e) {\n  // message was null: skip this dispatch cycle\n}","preventionTips":["Never construct PushConsumerContext from lookup results without a null check.","Prefer Optional<PushMessage> in your own message-resolution helpers.","Assert non-null in tests that build contexts manually."],"tags":["null-argument","constructor","push-consumer"],"backgroundTag":"null-argument","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"}