@@ -327,7 +327,7 @@ func buildCodecForTypeDescribedBySliceTwoWayJSON(st map[string]*Codec, enclosing
327327}
328328
329329func checkAll (allowedTypes []string , cr * codecInfo , buf []byte ) (interface {}, []byte , error ) {
330- for _ , name := range cr . allowedTypes {
330+ for _ , name := range allowedTypes {
331331 if name == "null" {
332332 // skip null since we know we already got type float64
333333 continue
@@ -344,6 +344,14 @@ func checkAll(allowedTypes []string, cr *codecInfo, buf []byte) (interface{}, []
344344 }
345345 return nil , buf , fmt .Errorf ("could not decode any json data in input %v" , string (buf ))
346346}
347+
348+ // sortedCopy returns a new slice that is a sorted copy of the provided types.
349+ func sortedCopy (allowedTypes []string ) []string {
350+ local := make ([]string , len (allowedTypes ))
351+ copy (local , allowedTypes )
352+ sort .Strings (local )
353+ return local
354+ }
347355func nativeAvroFromTextualJSON (cr * codecInfo ) func (buf []byte ) (interface {}, []byte , error ) {
348356 return func (buf []byte ) (interface {}, []byte , error ) {
349357
@@ -398,18 +406,14 @@ func nativeAvroFromTextualJSON(cr *codecInfo) func(buf []byte) (interface{}, []b
398406 // longNativeFromTextual
399407 // int
400408 // intNativeFromTextual
401-
402- // sorted so it would be
403- // double, float, int, long
404- // that makes the priorities right by chance
405- sort .Strings (cr .allowedTypes )
409+ allowedTypes = sortedCopy (allowedTypes )
406410
407411 case map [string ]interface {}:
408412
409413 // try to decode it as a map
410414 // because a map should fail faster than a record
411415 // if that fails assume record and return it
412- sort . Strings ( cr . allowedTypes )
416+ allowedTypes = sortedCopy ( allowedTypes )
413417 }
414418
415419 return checkAll (allowedTypes , cr , buf )
0 commit comments