[
https://issues.apache.org/jira/browse/AVRO-999?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
James Baldassari updated AVRO-999:
----------------------------------
Attachment: AVRO-999.patch
Good catch. Here's a patch with a unit test for this case.
> NPE in Java, RecordBuilderBase.defaultValue
> -------------------------------------------
>
> Key: AVRO-999
> URL: https://issues.apache.org/jira/browse/AVRO-999
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.6.1
> Environment: Java
> Reporter: Jay Rutten
> Attachments: AVRO-999.patch
>
>
> If you have a union with a default of null, the code in
> RecordBuilderBase.defaultValue will cause an NPE in ConcurrentHashMap, since
> it is trying to add a null to the map.
> Sample union:
> {code}
> record Sample {
> union{null, string} value = null;
> }
> {code}
> Code:
> {code}
> // If not cached, get the default Java value by encoding the default JSON
> // value and then decoding it:
> if (defaultValue == null) {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> encoder = EncoderFactory.get().binaryEncoder(baos, encoder);
> ResolvingGrammarGenerator.encode(encoder, field.schema(), defaultJsonValue);
> encoder.flush();
> decoder = DecoderFactory.get().binaryDecoder(baos.toByteArray(), decoder);
> defaultValue = new GenericDatumReader(field.schema()).read(null, decoder);
> defaultSchemaValues.putIfAbsent(field.pos(), defaultValue); // <-- NPE from
> here
> }
> {code}
--
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