[
https://issues.apache.org/jira/browse/AVRO-2278?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17113978#comment-17113978
]
ASF subversion and git services commented on AVRO-2278:
-------------------------------------------------------
Commit 3a098e8be4944216f811211c9e3240fd6f67a4ae in avro's branch
refs/heads/master from Zoltan Farkas
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=3a098e8 ]
[AVRO-2278] getter semantics confusing. (#864)
* [fix] getter semantics confusing.
impossible to distinguish between a correct field with the value null.
and a nonsense field.
* [fix]delete soem generated class
* [fix]delete soem generated class
* [fix]delete soem generated class
* [add] sync up exception behavior for consistency, and better messages.
* [add] helper method.
> GenericData.Record field getter not correct
> -------------------------------------------
>
> Key: AVRO-2278
> URL: https://issues.apache.org/jira/browse/AVRO-2278
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.8.2, 1.9.2
> Reporter: Zoltan Farkas
> Assignee: Zoltan Farkas
> Priority: Major
>
> Currently the get field implementation is not correct in GenericData.Record:
> at:
> https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java#L209
> {code}
> @Override public Object get(String key) {
> Field field = schema.getField(key);
> if (field == null) return null;
> return values[field.pos()];
> }
> {code}
> The method returns null when a field is not present, making it impossible to
> distinguish between:
> field value = null
> and
> field does not exist.
> A more "correct" implementation would be:
> {code}
> @Override public Object get(String key) {
> Field field = schema.getField(key);
> if (field == null) {
> throw new IllegalArgumentException("Invalid field " + key);
> }
> return values[field.pos()];
> }
> {code}
> this will make the behavior consistent with put which will throw a exception
> when setting a non existent field.
> when I make this change in my fork, some bugs in unit tests showed up....
--
This message was sent by Atlassian Jira
(v8.3.4#803005)