[
https://issues.apache.org/jira/browse/AVRO-1007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13203991#comment-13203991
]
Scott Carey commented on AVRO-1007:
-----------------------------------
I am not sure I see how this makes the Builder API respect the spec. Does it
allow the following?
{noformat}
{"type":"record", "name":"Person", "fields":[
{"name":"address", "type": ["null", "string"]}
]}
Person.newBuilder().build(); // should error, address has no explicit default
{noformat}
?
If so, to adhere to the spec that should throw an error since address was not
set and has no specified default.
Or, if the above is allowed, it is consistent to allow it regardless of the
order in the union. Either we enforce that all fields without a specified
default must be set, or allow for nullable fields to build without being set.
Half way in between seems inconsistent. In short, either we interpret an unset
field as an unset field that is only valid if there is a default, or we
interpret it as a null, which is valid for null schemas or unions with any
branch null.
A related case is below:
{noformat}
{"type":"record", "name":"Nothing", "fields":[
{"name":"blank", "type": "null"}
]}
Nothing.newBuilder().build(); // should error, blank not set and has no
explicit default
{noformat}
> Insufficient validation in generated specific record builder implementations
> ----------------------------------------------------------------------------
>
> Key: AVRO-1007
> URL: https://issues.apache.org/jira/browse/AVRO-1007
> Project: Avro
> Issue Type: Bug
> Affects Versions: 1.6.1
> Reporter: James Baldassari
> Assignee: James Baldassari
> Labels: java
> Fix For: 1.6.2
>
> Attachments: AVRO-1007-v2.patch, AVRO-1007-v3.patch,
> AVRO-1007-v4.patch, AVRO-1007.patch, AVRO-1007.patch, AVRO-1007.patch
>
>
> The are two main problems with the generated build() method in specific
> record builders:
> * For non-primitive types, if there is no default value and the user does not
> set the value, build() will execute successfully without throwing an exception
> ** Instead, an AvroRuntimeException should be thrown with an exception
> message indicating the name of the required field that was not set
> * For primitive types, if there is no default value and the user does not set
> the value, an AvroRuntimeException is thrown with the 'cause' set to a
> NullPointerException, which is not very helpful
> ** The NPE comes from attempting to set the primitive field to the result of
> defaultValue(), which is null
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira