Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLIENT] fixed NPE in GenericJsonRecord #10482

Merged
merged 2 commits into from
May 5, 2021

Conversation

abhilashmandaliya
Copy link
Contributor

Fixes #10472

Motivation

GenericJsonRecord should not error out if the non-existent field is queried.

Modifications

Added a null check and returning null if the field does not exist.

Verifying this change

Extended one of the tests for GenericJsonRecord.

@abhilashmandaliya
Copy link
Contributor Author

@abhilashmandaliya abhilashmandaliya changed the title fixed NPE in GenericJsonRecord [CLIENT] fixed NPE in GenericJsonRecord May 5, 2021
JSONSchema<PC> schema2 = JSONSchema.of(PC.class);
org.apache.avro.Schema avroSchema2 = (Schema) schema2.getNativeSchema().get();
org.apache.avro.Schema avroSchema2 =
(Schema) schema2.getNativeSchema().orElseThrow(IllegalAccessException::new);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

Copy link
Contributor Author

@abhilashmandaliya abhilashmandaliya May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was unsafe to call get on optional without checking it. hence I added this exception there. intellij showed a warning there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I fixed it as it was just a test class so should not cause any unexpected behaviour

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a test case, I am not sure it is worth to complicate it.
the test would fail anyway, we are only making the line longer IMHO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the possible "unsafe call to get" should be fine in this context (in test code).

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good
I left a little comment, non blocker

+1

JSONSchema<PC> schema2 = JSONSchema.of(PC.class);
org.apache.avro.Schema avroSchema2 = (Schema) schema2.getNativeSchema().get();
org.apache.avro.Schema avroSchema2 =
(Schema) schema2.getNativeSchema().orElseThrow(IllegalAccessException::new);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a test case, I am not sure it is worth to complicate it.
the test would fail anyway, we are only making the line longer IMHO

@abhilashmandaliya
Copy link
Contributor Author

overall looks good
I left a little comment, non blocker

+1

Thanks, @eolivelli . Yeah, it's just a test and made it a little longer 😅 but the idea warning irritates me so I changed it along with other changes in this file.

@abhilashmandaliya
Copy link
Contributor Author

/pulsarbot run-failure-checks

@abhilashmandaliya
Copy link
Contributor Author

@lhotari @eolivelli I have reverted additional changes :)

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@abhilashmandaliya
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie added this to the 2.8.0 milestone May 5, 2021
@sijie sijie merged commit ff076e3 into apache:master May 5, 2021
@abhilashmandaliya abhilashmandaliya deleted the PULSAR-10472 branch May 6, 2021 04:39
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request May 11, 2021
Fixes apache#10472

### Motivation
GenericJsonRecord should not error out if the non-existent field is queried.

### Modifications

Added a null check and returning null if the field does not exist.

### Verifying this change

Extended one of the tests for GenericJsonRecord.
eolivelli pushed a commit to datastax/pulsar that referenced this pull request May 20, 2021
Fixes apache#10472

GenericJsonRecord should not error out if the non-existent field is queried.

Added a null check and returning null if the field does not exist.

Extended one of the tests for GenericJsonRecord.

(cherry picked from commit ff076e3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GenericJsonRecord throws NPE
4 participants