Skip to content

Commit

Permalink
Polish "Make sure NoUniqueBeanDefinitionException to be serializable"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Aug 27, 2023
1 parent 1b409d5 commit 1396daa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package org.springframework.beans.factory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

Expand Down Expand Up @@ -61,7 +62,7 @@ public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNam
super(type, "expected single matching bean but found " + beanNamesFound.size() + ": " +
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
this.numberOfBeansFound = beanNamesFound.size();
this.beanNamesFound = beanNamesFound;
this.beanNamesFound = new ArrayList<>(beanNamesFound);
}

/**
Expand All @@ -83,7 +84,7 @@ public NoUniqueBeanDefinitionException(ResolvableType type, Collection<String> b
super(type, "expected single matching bean but found " + beanNamesFound.size() + ": " +
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
this.numberOfBeansFound = beanNamesFound.size();
this.beanNamesFound = beanNamesFound;
this.beanNamesFound = new ArrayList<>(beanNamesFound);
}

/**
Expand Down
Expand Up @@ -21,7 +21,6 @@
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;

Expand Down Expand Up @@ -216,7 +215,7 @@ public boolean isEager() {
*/
@Nullable
public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException {
throw new NoUniqueBeanDefinitionException(type, new HashSet<>( matchingBeans.keySet() ));
throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());
}

/**
Expand Down
Expand Up @@ -30,7 +30,6 @@
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;
Expand Down Expand Up @@ -1297,7 +1296,7 @@ else if (candidateNames.length > 1) {
return new NamedBeanHolder<>(candidateName, (T) beanInstance);
}
if (!nonUniqueAsNull) {
throw new NoUniqueBeanDefinitionException(requiredType, new HashSet<>(candidates.keySet()));
throw new NoUniqueBeanDefinitionException(requiredType, candidates.keySet());
}
}

Expand Down

0 comments on commit 1396daa

Please sign in to comment.