avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Cutting (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-999) NPE in Java, RecordBuilderBase.defaultValue
Date Thu, 23 Feb 2012 18:24:49 GMT

    [ https://issues.apache.org/jira/browse/AVRO-999?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214909#comment-13214909
] 

Doug Cutting commented on AVRO-999:
-----------------------------------

The test case added in this patch passes with the changes in AVRO-1007.  Also, the tests added
in AVRO-1007 are substantially similar to the test added here.
                
> 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
>            Assignee: James Baldassari
>         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

        

Mime
View raw message