Bird
0
0

What is the output of this Kafka Streams processor code if the input record value is null?

medium📝 Predict Output Q5 of 15
Kafka - Advanced Stream Processing
What is the output of this Kafka Streams processor code if the input record value is null?
stream.mapValues(value -> {
  try {
    return value.toLowerCase();
  } catch (Exception e) {
    return "error";
  }
});
AException thrown, stream stops
Bnull
C"NULL"
D"error"
Step-by-Step Solution
Solution:
  1. Step 1: Trace code with null input

    Calling toLowerCase() on null throws NullPointerException caught by catch block.
  2. Step 2: Check catch block return value

    Catch block returns string "error" when exception occurs.
  3. Final Answer:

    "error" -> Option D
  4. Quick Check:

    Exception caught returns "error" [OK]
Quick Trick: Catch exceptions to return fallback values [OK]
Common Mistakes:
MISTAKES
  • Expecting null output instead of fallback
  • Thinking exception stops stream here
  • Confusing uppercase with lowercase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes