Properly handle nil interfaces in DeepCopy.

Running reflect.ValueOf(X) where X is a nil interface will return
a zero Value. We cannot get the type (because no concrete type is
known) and cannot check if the Value is nil later on due to the way
reflect.Value works. So we should handle this case by immediately
returning nil. We cannot type-assert a nil interface to another
interface type (as no concrete type is assigned), so we must add
another check to see if the returned interface is nil.
This commit is contained in:
Muhammed Uluyol
2015-08-11 14:59:46 -07:00
parent 103a39c621
commit bc8bc37282
4 changed files with 23 additions and 0 deletions

View File

@@ -31,6 +31,8 @@ func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c
if in.Amount != nil {
if newVal, err := c.DeepCopy(in.Amount); err != nil {
return err
} else if newVal == nil {
out.Amount = nil
} else {
out.Amount = newVal.(*inf.Dec)
}