Make sure NoUniqueBeanDefinitionException to be serializable

See gh-29753
This commit is contained in:
Per Lundberg 2022-12-29 15:04:47 +02:00 committed by Stephane Nicoll
parent ca14202d78
commit 1b409d5290
2 changed files with 4 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
@ -215,7 +216,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
*/
@Nullable
public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException {
throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());
throw new NoUniqueBeanDefinitionException(type, new HashSet<>( matchingBeans.keySet() ));
}
/**

View File

@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
@ -1296,7 +1297,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return new NamedBeanHolder<>(candidateName, (T) beanInstance);
}
if (!nonUniqueAsNull) {
throw new NoUniqueBeanDefinitionException(requiredType, candidates.keySet());
throw new NoUniqueBeanDefinitionException(requiredType, new HashSet<>(candidates.keySet()));
}
}