diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java index f536581e68..f5aadabe3e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -155,8 +155,7 @@ public class EntityScanPackages { String[] basePackages = attributes.getStringArray("basePackages"); Class[] basePackageClasses = attributes .getClassArray("basePackageClasses"); - Set packagesToScan = new LinkedHashSet<>(); - packagesToScan.addAll(Arrays.asList(basePackages)); + Set packagesToScan = new LinkedHashSet<>(Arrays.asList(basePackages)); for (Class basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index fee427823a..7f4f1d3722 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -1185,8 +1185,7 @@ public class SpringApplication { */ public void setInitializers( Collection> initializers) { - this.initializers = new ArrayList<>(); - this.initializers.addAll(initializers); + this.initializers = new ArrayList<>(initializers); } /** @@ -1213,8 +1212,7 @@ public class SpringApplication { * @param listeners the listeners to set */ public void setListeners(Collection> listeners) { - this.listeners = new ArrayList<>(); - this.listeners.addAll(listeners); + this.listeners = new ArrayList<>(listeners); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java index 8fff79f065..80a06856c5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -132,9 +132,6 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope private Cache getCache() { CacheKey cacheKey = CacheKey.get(getPropertySource()); - if (cacheKey == null) { - return null; - } if (ObjectUtils.nullSafeEquals(cacheKey, this.cacheKey)) { return this.cache; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java index 649f1c049d..832109d635 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,8 +77,7 @@ class ServletComponentScanRegistrar implements ImportBeanDefinitionRegistrar { metadata.getAnnotationAttributes(ServletComponentScan.class.getName())); String[] basePackages = attributes.getStringArray("basePackages"); Class[] basePackageClasses = attributes.getClassArray("basePackageClasses"); - Set packagesToScan = new LinkedHashSet<>(); - packagesToScan.addAll(Arrays.asList(basePackages)); + Set packagesToScan = new LinkedHashSet<>(Arrays.asList(basePackages)); for (Class basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java index 7dc67e29b4..92bf8a1d98 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -238,8 +238,7 @@ public class ServletContextInitializerBeans } } } - List> beans = new ArrayList<>(); - beans.addAll(map.entrySet()); + List> beans = new ArrayList<>(map.entrySet()); beans.sort((o1, o2) -> AnnotationAwareOrderComparator.INSTANCE .compare(o1.getValue(), o2.getValue())); return beans; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 985e1ace37..31ac59be55 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -16,7 +16,6 @@ package org.springframework.boot; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -347,7 +346,7 @@ public class SpringApplicationTests { SpringApplication application = new SpringApplication(ExampleConfig.class); application.setWebApplicationType(WebApplicationType.NONE); final AtomicReference reference = new AtomicReference<>(); - application.setInitializers(Arrays.asList( + application.setInitializers(Collections.singletonList( (ApplicationContextInitializer) reference::set)); this.context = application.run("--foo=bar"); assertThat(this.context).isSameAs(reference.get()); @@ -387,7 +386,7 @@ public class SpringApplicationTests { } } - application.setListeners(Arrays.asList(new InitializerListener())); + application.setListeners(Collections.singletonList(new InitializerListener())); this.context = application.run("--foo=bar"); assertThat(this.context).isSameAs(reference.get()); // Custom initializers do not switch off the defaults diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ConfigurationsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ConfigurationsTests.java index 3cf240b0ea..3a2c362116 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ConfigurationsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ConfigurationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -21,6 +21,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.Set; @@ -59,7 +60,8 @@ public class ConfigurationsTests { public void getClassesShouldMergeByClassAndSort() { Configurations c1 = new TestSortedConfigurations( Arrays.asList(OutputStream.class, InputStream.class)); - Configurations c2 = new TestConfigurations(Arrays.asList(Short.class)); + Configurations c2 = new TestConfigurations( + Collections.singletonList(Short.class)); Configurations c3 = new TestSortedConfigurations( Arrays.asList(String.class, Integer.class)); Configurations c4 = new TestConfigurations(Arrays.asList(Long.class, Byte.class)); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 496aa5312a..3a1353c638 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -1054,8 +1053,8 @@ public class ConfigFileApplicationListenerTests { @Override List loadPostProcessors() { - return new ArrayList<>( - Arrays.asList(new LowestPrecedenceEnvironmentPostProcessor())); + return new ArrayList<>(Collections + .singletonList(new LowestPrecedenceEnvironmentPostProcessor())); } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index 10392ac316..11edff6307 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java @@ -21,6 +21,7 @@ import java.nio.charset.Charset; import java.time.Duration; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Locale; import java.util.Map; @@ -209,7 +210,7 @@ public class JettyServletWebServerFactoryTests @Test public void wrappedHandlers() throws Exception { JettyServletWebServerFactory factory = getFactory(); - factory.setServerCustomizers(Arrays.asList((server) -> { + factory.setServerCustomizers(Collections.singletonList((server) -> { Handler handler = server.getHandler(); HandlerWrapper wrapper = new HandlerWrapper(); wrapper.setHandler(handler); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java index 8e5e6f2dd9..2e4465af3a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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,8 +77,7 @@ public class MimeMappingsTests { MimeMappings mappings = new MimeMappings(); mappings.add("foo", "bar"); mappings.add("baz", "boo"); - List mappingList = new ArrayList<>(); - mappingList.addAll(mappings.getAll()); + List mappingList = new ArrayList<>(mappings.getAll()); assertThat(mappingList.get(0).getExtension()).isEqualTo("foo"); assertThat(mappingList.get(0).getMimeType()).isEqualTo("bar"); assertThat(mappingList.get(1).getExtension()).isEqualTo("baz"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java index 3e591416a0..1a6bd8a356 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -144,7 +144,7 @@ public abstract class AbstractFilterRegistrationBeanTests { AbstractFilterRegistrationBean bean = createFilterRegistrationBean( mockServletRegistration("a")); bean.setServletRegistrationBeans(new LinkedHashSet>( - Arrays.asList(mockServletRegistration("b")))); + Collections.singletonList(mockServletRegistration("b")))); bean.onStartup(this.servletContext); verify(this.registration).addMappingForServletNames( EnumSet.of(DispatcherType.REQUEST), false, "b"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java index c78a682ae2..f719f945a0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -16,7 +16,6 @@ package org.springframework.boot.web.servlet.support; -import java.util.Arrays; import java.util.Collections; import javax.servlet.ServletContext; @@ -135,8 +134,8 @@ public class SpringBootServletInitializerTests { @Test public void servletContextPropertySourceIsAvailablePriorToRefresh() { ServletContext servletContext = mock(ServletContext.class); - given(servletContext.getInitParameterNames()).willReturn( - Collections.enumeration(Arrays.asList("spring.profiles.active"))); + given(servletContext.getInitParameterNames()).willReturn(Collections + .enumeration(Collections.singletonList("spring.profiles.active"))); given(servletContext.getInitParameter("spring.profiles.active")) .willReturn("from-servlet-context"); given(servletContext.getAttributeNames())