Bird
0
0

What is wrong with this Kafka consumer subscription code?

medium📝 Debug Q7 of 15
Kafka - Consumers
What is wrong with this Kafka consumer subscription code?
List topics = null;
consumer.subscribe(topics);
AThe consumer must be closed before subscribing.
Btopics must be a Set, not a List.
Csubscribe() cannot be called without a consumer group ID.
Dtopics is null, causing a NullPointerException at runtime.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the value of topics

    topics is assigned null, so passing it to subscribe() will cause a runtime error.
  2. Step 2: Understand subscribe() behavior with null

    subscribe() expects a non-null collection; null causes NullPointerException.
  3. Final Answer:

    topics is null, causing a NullPointerException at runtime. -> Option D
  4. Quick Check:

    Passing null collection causes NullPointerException [OK]
Quick Trick: Never pass null to subscribe(); use empty list to unsubscribe [OK]
Common Mistakes:
  • Assuming null means unsubscribe
  • Thinking List vs Set matters here
  • Confusing consumer group ID with subscription

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes