[
https://issues.apache.org/jira/browse/AVRO-1600?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chris Wells updated AVRO-1600:
------------------------------
Reporter: Alfonso Nishikawa Muñumer (was: Alfonso Nishikawa)
> GenericData#getDefaultValue(Field) behavior inconsistent with javadoc comment
> when default value is not defined
> ---------------------------------------------------------------------------------------------------------------
>
> Key: AVRO-1600
> URL: https://issues.apache.org/jira/browse/AVRO-1600
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.7.4, 1.7.7
> Reporter: Alfonso Nishikawa Muñumer
> Priority: Trivial
>
> The behavior of {{GenericData#getDefaultValue(Field)}} when the default value
> is not defined in the schema is to throw an AvroRuntimeException.
> The javadoc comment states that should return {{null}} in this case. [This
> can be seen
> here|http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?view=markup#l872]:
> {code}
> /**
> * Gets the default value of the given field, if any.
> * @param field the field whose default value should be retrieved.
> * @return the default value associated with the given field,
> * or null if none is specified in the schema.
> */
> @SuppressWarnings({ "rawtypes", "unchecked" })
> public Object getDefaultValue(Field field) {
> JsonNode json = field.defaultValue();
> if (json == null)
> throw new AvroRuntimeException("Field " + field
> + " not set and has no default value");
> {code}
> This behavior affects {{RecordBuilderBase#defaultValue(Field)}} which expects
> a null too, [as stated in it's javadoc
> comment|http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java?view=markup#l125]:
> {code}
> /**
> * Gets the default value of the given field, if any.
> * @param field the field whose default value should be retrieved.
> * @return the default value associated with the given field,
> * or null if none is specified in the schema.
> * @throws IOException
> */
> @SuppressWarnings({ "rawtypes", "unchecked" })
> protected Object defaultValue(Field field) throws IOException {
> return data.deepCopy(field.schema(), data.getDefaultValue(field));
> }
> {code}
> Fix options:
> * Modify the javadoc to comment it throws a runtime exception (and people
> should take this into account).
> * Modify the method to return a null as stated in the javadoc comment.
> * Modify the method to return null when the field is nullable and the default
> value is not defined, and update javadoc. (was this the original intended
> behavior?)
--
This message was sent by Atlassian Jira
(v8.20.1#820001)