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

AVRO-1401: @Nullable does not work with byte[] #229

Closed
wants to merge 4 commits into from

Conversation

nandorKollar
Copy link
Contributor

No description provided.

@@ -181,13 +181,15 @@ protected boolean isRecord(Object datum) {

/**
* Returns true also for non-string-keyed maps, which are written as an array
* of key/value pair records.
* of key/value pair records. Returns false for array of bytes, since it should
Copy link

Choose a reason for hiding this comment

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

I find it a bit strange that the javadoc comment only documents the exception cases and not the main behavior. I would suggest the following instead:

Returns true for arrays and false otherwise, with the following exceptions:

  • Returns true for non-string-keyed maps, which are written as an array of key/value pair records.
  • Returns false for arrays of bytes, since those should be treated as byte data type instead.

return (datum instanceof Collection)
|| datum.getClass().isArray()
|| (c.isArray() && !(c.getComponentType() == Byte.TYPE))
Copy link

Choose a reason for hiding this comment

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

I would suggest c.getComponentType() != Byte.TYPE instead of !(c.getComponentType() == Byte.TYPE)

}

@Test
public void testNullableByteArray() throws IOException {
Copy link

Choose a reason for hiding this comment

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

Since there are no asserts in this test, could you document in a comment how this test would fail without the fix? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of documenting the test, I rewrote it. It asserts for the output in the updated version

@nandorKollar
Copy link
Contributor Author

@zivanfi thanks for you comments. Updated the pull request, could you please have a look at it and share you opinion?

* of key/value pair records.
* Returns true for arrays and false otherwise, with the following exceptions:
* <ul>
* <li><p>Returns true for non-string-keyed maps, which are written as an array of key/value pair records.</p></li>
Copy link

Choose a reason for hiding this comment

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

Nit: No need for the <p>-s inside the <li>-s.

* <ul>
* <li><p>Returns true for non-string-keyed maps, which are written as an array of key/value pair records.</p></li>
* <li><p>Returns false for arrays of bytes, since those should be treated as byte data type instead.</p></li>
* <ul>
Copy link

Choose a reason for hiding this comment

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

This should be </ul>

@nandorKollar
Copy link
Contributor Author

Fixed closing tag for list.


@Test
public void testNullableByteArray() throws Exception {
checkReadWrite(new NullableBytesTest());
Copy link
Contributor

Choose a reason for hiding this comment

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

As we are testing a nullable field I would also test the scenario when this field is really null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gszadovszky updated the pul request with an additional test case to cover null field value.

Copy link
Contributor

@gszadovszky gszadovszky left a comment

Choose a reason for hiding this comment

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

Thanks a lot. +1

@asfgit asfgit closed this in c04a17c Jun 14, 2017
asfgit pushed a commit that referenced this pull request Jun 14, 2017
This closes #229

(cherry picked from commit c04a17c)
SingingBush pushed a commit to SingingBush/avro that referenced this pull request Jun 29, 2023
Fix vulnerabilities in transitive dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants