-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Describe the bug
Calling GenericRecord.getField(Field field) on a GenericRecord that is a sub-record, where the field is a string, the Pulsar client throws a NullPointerException:
java.lang.NullPointerException
at org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord.isBinaryValue(GenericJsonRecord.java:110)
at org.apache.pulsar.client.impl.schema.generic.GenericJsonRecord.getField(GenericJsonRecord.java:87)
at org.apache.pulsar.client.api.schema.GenericRecord.getField(GenericRecord.java:53)
To Reproduce
Steps to reproduce the behavior:
- Using the Pulsar Java Client create a consumer of type Schema.AUTO_CONSUME, to receive GenericRecords from the broker.
- Fill the topic with messages with a subrecord with a string in it, in the form of a JsonSchema. This is an example schema:
{
"type": "JSON",
"schema": "{"type":"record","namespace":"com.example","name":"MyJsonSchema","fields":[{"name":"subrecord_field","type":{"type":"record","name":"subrecord_field","fields":[{"name":"substring_field","type":"string"}]}}]}",
"properties": {}
} - When a message is received, get the subrecord by calling .getField(Field field) on the top level record.
- The try to get the field for the substring field by calling .getField() on the subrecord.
Example code:
GenericRecord subRecord = record.getField("subrecord_field");
subRecord.getField("substring_field"); // This will throw a null pointer exception
Expected behavior
getField should return the Object that is the field. i.e. for this, we should get a String back.
Desktop (please complete the following information):
- OS: linux
Additional context
Pulsar client version 2.7.0