Avro
  1. Avro
  2. AVRO-999

NPE in Java, RecordBuilderBase.defaultValue

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.2
    • Component/s: java
    • Labels:
      None
    • Environment:

      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
      }
      
      1. AVRO-999.patch
        3 kB
        James Baldassari

        Activity

        Jay Rutten created issue -
        James Baldassari made changes -
        Field Original Value New Value
        Attachment AVRO-999.patch [ 12511210 ]
        James Baldassari made changes -
        Status Open [ 1 ] Patch Available [ 10002 ]
        Assignee James Baldassari [ jbaldassari ]
        Doug Cutting made changes -
        Status Patch Available [ 10002 ] Resolved [ 5 ]
        Assignee James Baldassari [ jbaldassari ]
        Resolution Duplicate [ 3 ]
        Scott Carey made changes -
        Fix Version/s 1.6.2 [ 12319074 ]
        Doug Cutting made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Jay Rutten
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development