Bird
0
0

What will happen if you call consumer.subscribe(null); in Kafka?

medium📝 Predict Output Q5 of 15
Kafka - Consumers
What will happen if you call consumer.subscribe(null); in Kafka?
AThe consumer will unsubscribe from all topics.
BThe consumer will throw a NullPointerException.
CThe consumer will subscribe to all available topics.
DThe consumer will ignore the call and keep current subscriptions.
Step-by-Step Solution
Solution:
  1. Step 1: Check the argument type for subscribe()

    subscribe() expects a non-null collection of topic names.
  2. Step 2: Understand behavior when null is passed

    Passing null causes a NullPointerException because the method tries to iterate over the collection.
  3. Final Answer:

    The consumer will throw a NullPointerException. -> Option B
  4. Quick Check:

    subscribe(null) causes NullPointerException [OK]
Quick Trick: Never pass null to subscribe(); use empty list to unsubscribe [OK]
Common Mistakes:
  • Thinking null unsubscribes consumer
  • Assuming null subscribes to all topics
  • Ignoring that null causes runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes