diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 7bf8cec7054..2f3896e90c3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -154,7 +154,9 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto methods.add(method); } }, ReflectionUtils.USER_DECLARED_METHODS); - methods.sort(METHOD_COMPARATOR); + if (methods.size() > 1) { + methods.sort(METHOD_COMPARATOR); + } return methods; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 746b4367a9f..1a3b76ea954 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -398,6 +398,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public Stream orderedStream() { String[] beanNames = getBeanNamesForTypedStream(requiredType); + if (beanNames.length == 0) { + return Stream.empty(); + } Map matchingBeans = new LinkedHashMap<>(beanNames.length); for (String beanName : beanNames) { Object beanInstance = getBean(beanName); @@ -1366,9 +1369,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter()); Object result = converter.convertIfNecessary(matchingBeans.values(), type); if (result instanceof List) { - Comparator comparator = adaptDependencyComparator(matchingBeans); - if (comparator != null) { - ((List) result).sort(comparator); + if (((List) result).size() > 1) { + Comparator comparator = adaptDependencyComparator(matchingBeans); + if (comparator != null) { + ((List) result).sort(comparator); + } } } return result; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java index 3bd28717c6e..d8474303a05 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -76,7 +76,9 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition(parseExpressions(consumes, headers)); - Collections.sort(this.expressions); + if (this.expressions.size() > 1) { + Collections.sort(this.expressions); + } } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java index dfe4b6e98ec..a6cee7b9906 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -93,7 +93,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition(parseExpressions(produces, headers)); - Collections.sort(this.expressions); + if (this.expressions.size() > 1) { + Collections.sort(this.expressions); + } this.contentTypeResolver = resolver != null ? resolver : DEFAULT_CONTENT_TYPE_RESOLVER; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java index ae832d4cadd..66fabb42a1f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -77,7 +77,9 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition(parseExpressions(consumes, headers)); - Collections.sort(this.expressions); + if (this.expressions.size() > 1) { + Collections.sort(this.expressions); + } } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java index 7bad3a02522..b031c7fc42e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -97,7 +97,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition(parseExpressions(produces, headers)); - Collections.sort(this.expressions); + if (this.expressions.size() > 1) { + Collections.sort(this.expressions); + } this.contentNegotiationManager = manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER; }