Merge pull request #12556 from uluyol/copynilinterface

Properly handle nil interfaces in DeepCopy.
This commit is contained in:
Piotr Szczesniak
2015-08-12 09:54:02 +02:00
4 changed files with 23 additions and 0 deletions

View File

@@ -117,6 +117,13 @@ func (c *Cloner) RegisterGeneratedDeepCopyFunc(deepCopyFunc interface{}) error {
// DeepCopy will perform a deep copy of a given object.
func (c *Cloner) DeepCopy(in interface{}) (interface{}, error) {
// Can be invalid if we run DeepCopy(X) where X is a nil interface type.
// For example, we get an invalid value when someone tries to deep-copy
// a nil labels.Selector.
// This does not occur if X is nil and is a pointer to a concrete type.
if in == nil {
return nil, nil
}
inValue := reflect.ValueOf(in)
outValue, err := c.deepCopy(inValue)
if err != nil {