diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 40aa1c95f7..b5c8b87ed8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -378,7 +378,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut } catch (Throwable ex) { if (logger.isDebugEnabled()) { - logger.debug("Failed to evaluate join point for arguments " + Arrays.asList(args) + + logger.debug("Failed to evaluate join point for arguments " + Arrays.toString(args) + " - falling back to non-match", ex); } return false; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java index 64975e98af..4f5d563ca0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java @@ -424,7 +424,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport if (!this.advisorChainInitialized && !ObjectUtils.isEmpty(this.interceptorNames)) { if (this.beanFactory == null) { throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " + - "- cannot resolve interceptor names " + Arrays.asList(this.interceptorNames)); + "- cannot resolve interceptor names " + Arrays.toString(this.interceptorNames)); } // Globals can't be last unless we specified a targetSource using the property... diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java index 2814670194..fbf3970719 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java @@ -17,7 +17,7 @@ package org.springframework.beans.factory.support; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.springframework.beans.BeanMetadataElement; @@ -31,6 +31,8 @@ import org.springframework.lang.Nullable; * @author Rod Johnson * @author Rob Harrop * @author Juergen Hoeller + * @author Stephane Nicoll + * @author Sam Brannen * @since 27.05.2003 * @param the element type */ @@ -55,16 +57,16 @@ public class ManagedList extends ArrayList implements Mergeable, BeanMetad /** - * Return a new instance containing an arbitrary number of elements. + * Create a new instance containing an arbitrary number of elements. * @param elements the elements to be contained in the list * @param the {@code List}'s element type - * @return a {@code List} containing the specified elements + * @return a {@code ManagedList} containing the specified elements * @since 5.3.16 */ - @SuppressWarnings("unchecked") + @SafeVarargs public static ManagedList of(E... elements) { ManagedList list = new ManagedList<>(); - list.addAll(Arrays.asList(elements)); + Collections.addAll(list, elements); return list; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java index f5c7246237..8bc4152aea 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java @@ -16,7 +16,7 @@ package org.springframework.beans.factory.support; -import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; @@ -30,6 +30,8 @@ import org.springframework.lang.Nullable; * * @author Juergen Hoeller * @author Rob Harrop + * @author Stephane Nicoll + * @author Sam Brannen * @since 21.01.2004 * @param the element type */ @@ -54,16 +56,16 @@ public class ManagedSet extends LinkedHashSet implements Mergeable, BeanMe /** - * Return a new instance containing an arbitrary number of elements. + * Create a new instance containing an arbitrary number of elements. * @param elements the elements to be contained in the set * @param the {@code Set}'s element type - * @return a {@code Set} containing the specified elements + * @return a {@code ManagedSet} containing the specified elements * @since 5.3.16 */ - @SuppressWarnings("unchecked") + @SafeVarargs public static ManagedSet of(E... elements) { ManagedSet set = new ManagedSet<>(); - set.addAll(Arrays.asList(elements)); + Collections.addAll(set, elements); return set; } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedListTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedListTests.java index 420226d173..9d8a1cbe36 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedListTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedListTests.java @@ -25,61 +25,61 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** + * Unit tests for {@link ManagedList}. + * * @author Rick Evans * @author Juergen Hoeller * @author Sam Brannen */ @SuppressWarnings({ "rawtypes", "unchecked" }) -public class ManagedListTests { +class ManagedListTests { @Test - public void mergeSunnyDay() { + void mergeSunnyDay() { ManagedList parent = ManagedList.of("one", "two"); ManagedList child = ManagedList.of("three"); child.setMergeEnabled(true); List mergedList = child.merge(parent); - assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(3); + assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two", "three"); } @Test - public void mergeWithNullParent() { + void mergeWithNullParent() { ManagedList child = ManagedList.of("one"); child.setMergeEnabled(true); assertThat(child.merge(null)).isSameAs(child); } @Test - public void mergeNotAllowedWhenMergeNotEnabled() { + void mergeNotAllowedWhenMergeNotEnabled() { ManagedList child = new ManagedList(); - assertThatIllegalStateException().isThrownBy(() -> - child.merge(null)); + assertThatIllegalStateException().isThrownBy(() -> child.merge(null)); } @Test - public void mergeWithNonCompatibleParentType() { + void mergeWithIncompatibleParentType() { ManagedList child = ManagedList.of("one"); child.setMergeEnabled(true); - assertThatIllegalArgumentException().isThrownBy(() -> - child.merge("hello")); + assertThatIllegalArgumentException().isThrownBy(() -> child.merge("hello")); } @Test - public void mergeEmptyChild() { + void mergeEmptyChild() { ManagedList parent = ManagedList.of("one", "two"); ManagedList child = new ManagedList(); child.setMergeEnabled(true); List mergedList = child.merge(parent); - assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(2); + assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two"); } @Test - public void mergeChildValuesOverrideTheParents() { + void mergedChildValuesDoNotOverrideTheParents() { // doesn't make much sense in the context of a list... ManagedList parent = ManagedList.of("one", "two"); ManagedList child = ManagedList.of("one"); child.setMergeEnabled(true); List mergedList = child.merge(parent); - assertThat(mergedList.size()).as("merge() obviously did not work.").isEqualTo(3); + assertThat(mergedList).as("merge() obviously did not work.").containsExactly("one", "two", "one"); } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedSetTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedSetTests.java index c11a63a6da..01f330f1c5 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedSetTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedSetTests.java @@ -25,61 +25,62 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** + * Unit tests for {@link ManagedSet}. + * * @author Rick Evans * @author Juergen Hoeller * @author Sam Brannen */ @SuppressWarnings({ "rawtypes", "unchecked" }) -public class ManagedSetTests { +class ManagedSetTests { @Test - public void mergeSunnyDay() { + void mergeSunnyDay() { ManagedSet parent = ManagedSet.of("one", "two"); ManagedSet child = ManagedSet.of("three"); child.add("three"); + child.add("four"); child.setMergeEnabled(true); Set mergedSet = child.merge(parent); - assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(3); + assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two", "three", "four"); } @Test - public void mergeWithNullParent() { + void mergeWithNullParent() { ManagedSet child = ManagedSet.of("one"); child.setMergeEnabled(true); assertThat(child.merge(null)).isSameAs(child); } @Test - public void mergeNotAllowedWhenMergeNotEnabled() { - assertThatIllegalStateException().isThrownBy(() -> - new ManagedSet().merge(null)); + void mergeNotAllowedWhenMergeNotEnabled() { + assertThatIllegalStateException().isThrownBy(() -> new ManagedSet().merge(null)); } @Test - public void mergeWithNonCompatibleParentType() { + void mergeWithNonCompatibleParentType() { ManagedSet child = ManagedSet.of("one"); child.setMergeEnabled(true); - assertThatIllegalArgumentException().isThrownBy(() -> - child.merge("hello")); + assertThatIllegalArgumentException().isThrownBy(() -> child.merge("hello")); } @Test - public void mergeEmptyChild() { + void mergeEmptyChild() { ManagedSet parent = ManagedSet.of("one", "two"); ManagedSet child = new ManagedSet(); child.setMergeEnabled(true); Set mergedSet = child.merge(parent); - assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(2); + assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two"); } @Test - public void mergeChildValuesOverrideTheParents() { + void mergeChildValuesOverrideTheParents() { // asserts that the set contract is not violated during a merge() operation... ManagedSet parent = ManagedSet.of("one", "two"); ManagedSet child = ManagedSet.of("one"); child.setMergeEnabled(true); Set mergedSet = child.merge(parent); - assertThat(mergedSet.size()).as("merge() obviously did not work.").isEqualTo(2); + assertThat(mergedSet).as("merge() obviously did not work.").containsExactly("one", "two"); } } diff --git a/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java b/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java index 3a369bbfb7..cc947ab702 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -143,7 +143,7 @@ public class NotificationListenerRegistrar extends NotificationListenerHolder this.actualObjectNames = getResolvedObjectNames(); if (this.actualObjectNames != null) { if (logger.isDebugEnabled()) { - logger.debug("Registering NotificationListener for MBeans " + Arrays.asList(this.actualObjectNames)); + logger.debug("Registering NotificationListener for MBeans " + Arrays.toString(this.actualObjectNames)); } for (ObjectName actualObjectName : this.actualObjectNames) { this.server.addNotificationListener( diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index bb197df43f..e789725c69 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -297,7 +297,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { public void setActiveProfiles(String... profiles) { Assert.notNull(profiles, "Profile array must not be null"); if (logger.isDebugEnabled()) { - logger.debug("Activating profiles " + Arrays.asList(profiles)); + logger.debug("Activating profiles " + Arrays.toString(profiles)); } synchronized (this.activeProfiles) { this.activeProfiles.clear(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index d7ab9ab380..5d6d83c142 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -451,7 +451,7 @@ public abstract class AbstractJdbcInsert { if (getGeneratedKeyNames().length > 1) { throw new InvalidDataAccessApiUsageException( "Current database only supports retrieving the key for a single column. There are " + - getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames())); + getGeneratedKeyNames().length + " columns specified: " + Arrays.toString(getGeneratedKeyNames())); } Assert.state(getTableName() != null, "No table name set"); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java index a27654b865..6a94c993ef 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2022 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. @@ -117,7 +117,7 @@ public class SpringConfigurator extends Configurator { beanNamesByType.put(endpointClass, NO_VALUE); if (names.length > 1) { throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" + - endpointClass.getName() + "]: bean names " + Arrays.asList(names)); + endpointClass.getName() + "]: bean names " + Arrays.toString(names)); } } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java index 9841c19bd4..53869a25c0 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -83,7 +83,7 @@ public abstract class AbstractHttpReceivingTransportHandler extends AbstractTran return; } if (logger.isTraceEnabled()) { - logger.trace("Received message(s): " + Arrays.asList(messages)); + logger.trace("Received message(s): " + Arrays.toString(messages)); } response.setStatusCode(getResponseStatus()); response.getHeaders().setContentType(new MediaType("text", "plain", StandardCharsets.UTF_8));