avro-dev mailing list archives

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

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

James Baldassari commented on AVRO-999:
---------------------------------------

I think AVRO-999 is slightly different from AVRO-1007 as AVRO-999 is specifically related
to unions with null types.  I'm not positive, though.  Either way I think we should commit
the new test case this patch introduces to TestGenericRecordBuilder.  That should verify whether
the changes in AVRO-1007 actually fix this problem.
                
> 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