Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-999

NPE in Java, RecordBuilderBase.defaultValue

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.6.1
    • 1.6.2
    • java
    • None
    • Java

    Description

      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:

      record Sample {
          union{null, string} value = null;
      }
      

      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
      }
      

      Attachments

        1. AVRO-999.patch
          3 kB
          James Baldassari

        Activity

          People

            Unassigned Unassigned
            jrutten Jay Rutten
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: