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:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user