Bird
0
0

What is the issue with this Kafka deserializer implementation?

medium📝 Debug Q7 of 15
Kafka - Advanced Stream Processing

What is the issue with this Kafka deserializer implementation?

public class StringDeserializer implements Deserializer {
    public String deserialize(String topic, byte[] data) {
        return new String(data);
    }
}
AIt incorrectly converts bytes to uppercase strings.
BIt does not handle null byte arrays, which can cause NullPointerException.
CIt uses an unsupported character encoding.
DIt returns a byte array instead of a String.
Step-by-Step Solution
Solution:
  1. Step 1: Review deserialize method

    Method calls new String(data) without checking if data is null.
  2. Step 2: Identify potential error

    If data is null, new String(data) throws NullPointerException.
  3. Step 3: Correct approach

    Should check if data is null and return null or handle accordingly.
  4. Final Answer:

    It does not handle null byte arrays, which can cause NullPointerException. -> Option B
  5. Quick Check:

    Always check for null before converting bytes [OK]
Quick Trick: Null byte arrays cause exceptions if unchecked [OK]
Common Mistakes:
MISTAKES
  • Ignoring null checks on input byte arrays
  • Assuming default charset without specifying

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes