Skip to content

Java Client: NullPointerException with GenericRecord.getField() on a sub-record #9697

@epsteina16

Description

@epsteina16

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:

  1. Using the Pulsar Java Client create a consumer of type Schema.AUTO_CONSUME, to receive GenericRecords from the broker.
  2. 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": {}
    }
  3. When a message is received, get the subrecord by calling .getField(Field field) on the top level record.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions