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

@Nullable does not work with byte[]

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.7.5
    • 1.9.0
    • java

    Description

      @Nullable does not seem to be compatible with byte[] (Avro type bytes)

      public static void main(String[] args) throws IOException
      {
          Schema schema = ReflectData.get().getSchema(MyRecord.class);
          DatumWriter<?> protocol = ReflectData.get().createDatumWriter(schema);
          DataFileWriter<MyRecord> writer = new DataFileWriter(protocol).create(schema, System.out);
          writer.append(new MyRecord());
          writer.close();
      }
      
      public static class MyRecord {
          @Nullable
          byte[] bytes = "foo".getBytes();
      }
      
      org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"bytes","java-class":"[B"}]: [B@6d3f1f92
      	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:600)
      	at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:151)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:71)
      	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:143)
      	at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:114)
      	at org.apache.avro.reflect.ReflectDatumWriter.writeField(ReflectDatumWriter.java:175)
      	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:66)
      	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:143)
      	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:58)
      	at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:257)
      

      Attachments

        Issue Links

          Activity

            People

              nkollar Nándor Kollár
              striderapache dennis lucero
              Votes:
              2 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: