redis/jedis · error · IllegalArgumentException

Message cannot be null

Error message

Message cannot be null

What it means

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.

Solutions

  1. Ensure the PushMessage passed to the constructor is non-null before constructing the context.
  2. If the message comes from a lookup, check for null and handle the 'no message' case instead of building a context.
  3. Catch IllegalArgumentException at the call site as a last-resort guard in generic dispatch code.

Example fix

// before
PushMessage msg = pending.get(id);
PushConsumerContext ctx = new PushConsumerContext(msg);

// after
PushMessage msg = pending.get(id);
if (msg == null) {
  throw new IllegalStateException("No push message pending for id " + id);
}
PushConsumerContext ctx = new PushConsumerContext(msg);
Defensive patterns

Strategy: validation

Validate before calling

if (message == null) {
  throw new IllegalStateException("PushMessage must be resolved before building PushConsumerContext");
}
PushConsumerContext ctx = new PushConsumerContext(message);

Type guard

boolean hasMessage(PushMessage m) { return m != null; }

Try / catch

try {
  PushConsumerContext ctx = new PushConsumerContext(message);
} catch (IllegalArgumentException e) {
  // message was null: skip this dispatch cycle
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/c7f87c3babdea743. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/PushConsumerContext.java:30

 * Consumers can inspect the message and decide weather to :
 * <ul>
 * <li>return to the caller and skip the rest of consumers by calling
 * {@link PushConsumerContext#propagate()}</li>
 * <li>drop message without processing it further by calling {@link PushConsumerContext#drop()}
 * to</li>
 * <li>inspect and let it be processed by following consumers</li>
 * </ul>
 */
@Experimental
public class PushConsumerContext {
  private final PushMessage message;

  private boolean propagate = false;
  private boolean drop = false;

  public PushConsumerContext(PushMessage message) {
    if (message == null) {
      throw new IllegalArgumentException("Message cannot be null");
    }
    this.message = message;
  }

  /**
   * Get the push message being processed.
   * @return The push message
   */
  public PushMessage getMessage() {
    return message;
  }

  /**
   * Check if the message should be returned to the caller.
   * @return true if the message should be returned to the caller
   */
  public boolean shouldPropagate() {
    return propagate;

View on GitHub (pinned to 6dac31d4c2)