Bird
0
0

Why does the following code throw an exception at runtime?

medium📝 Debug Q7 of 15
Kafka - Advanced Stream Processing

Why does the following code throw an exception at runtime?

ReadOnlyKeyValueStore<String, String> store = streams.store("myStore", QueryableStoreTypes.keyValueStore());
String val = store.get(null);
Astore.get() requires a non-empty string key
BNull keys are not allowed in state stores
Cstore.get() only accepts integer keys
DThe store was not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Understand key constraints in state stores

    State stores do not allow null keys; passing null causes exceptions.
  2. Step 2: Analyze the code behavior

    Calling store.get(null) triggers an exception due to invalid key.
  3. Final Answer:

    Null keys are not allowed in state stores -> Option B
  4. Quick Check:

    Null keys cause exceptions in state stores [OK]
Quick Trick: Never pass null as key to store.get() [OK]
Common Mistakes:
  • Thinking empty string keys cause errors
  • Assuming integer keys only
  • Ignoring store initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes