@@ -269,6 +269,52 @@ func TestComplexOfComplexBinding(t *testing.T) {
269
269
}
270
270
}
271
271
272
+ // TestSpecificArrayCrash tests against regression of a crash scenario
273
+ // The crash occurs when an array decodes an explicitly nil value (like in a
274
+ // type union). The type union works fine as a raw field but not in an array.
275
+ func TestSpecificArrayCrash (t * testing.T ) {
276
+ schema := MustParseSchema (`{
277
+ "type": "record",
278
+ "name": "Rec",
279
+ "fields": [{
280
+ "name": "a",
281
+ "type": {
282
+ "type": "array",
283
+ "items": ["null", "string", "long", "float"]
284
+ }
285
+ }]
286
+ }` )
287
+ type Rec struct {
288
+ A []interface {} `avro:"a"`
289
+ }
290
+ // Write some bytes
291
+ var buf bytes.Buffer
292
+ writer := NewSpecificDatumWriter ()
293
+ writer .SetSchema (schema )
294
+ prims := []interface {}{
295
+ "foo" ,
296
+ nil ,
297
+ int64 (7 ),
298
+ }
299
+ writer .Write (& Rec {prims }, NewBinaryEncoder (& buf ))
300
+
301
+ // Now do the read. This will crash if there's any null setting issue.
302
+ var dest Rec
303
+ reader := NewSpecificDatumReader ()
304
+ reader .SetSchema (schema )
305
+ err := reader .Read (& dest , NewBinaryDecoder (buf .Bytes ()))
306
+ if err != nil {
307
+ t .Fatal (err )
308
+ }
309
+ if len (dest .A ) != 3 {
310
+ t .Fatalf ("A must be 3, got %d" , len (dest .A ))
311
+ }
312
+ assert (t , dest .A [0 ], "foo" )
313
+ assert (t , dest .A [1 ], nil )
314
+ assert (t , dest .A [2 ], int64 (7 ))
315
+
316
+ }
317
+
272
318
func TestGenericDatumReaderEmptyMap (t * testing.T ) {
273
319
sch , err := ParseSchema (`{
274
320
"type": "record",
0 commit comments