diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index 0aea6a04cb..6877a54ab9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -88,8 +88,7 @@ class AutoConfigurationSorter { } processing.add(current); for (String after : classes.getClassesRequestedAfter(current)) { - Assert.state(!processing.contains(after), - "AutoConfigure cycle detected between " + current + " and " + after); + checkForCycles(processing, current, after); if (!sorted.contains(after) && toSort.contains(after)) { doSortByAfterAnnotation(classes, toSort, sorted, processing, after); } @@ -98,6 +97,11 @@ class AutoConfigurationSorter { sorted.add(current); } + private void checkForCycles(Set processing, String current, String after) { + Assert.state(!processing.contains(after), + () -> "AutoConfigure cycle detected between " + current + " and " + after); + } + private static class AutoConfigurationClasses { private final Map classes = new HashMap<>(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java index 78341207e1..a7368e5e46 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java @@ -111,7 +111,7 @@ class Saml2RelyingPartyRegistrationConfiguration { private RSAPrivateKey readPrivateKey(Resource location) { Assert.state(location != null, "No private key location specified"); - Assert.state(location.exists(), "Private key location '" + location + "' does not exist"); + Assert.state(location.exists(), () -> "Private key location '" + location + "' does not exist"); try (InputStream inputStream = location.getInputStream()) { return RsaKeyConverters.pkcs8().convert(inputStream); } @@ -122,7 +122,7 @@ class Saml2RelyingPartyRegistrationConfiguration { private X509Certificate readCertificate(Resource location) { Assert.state(location != null, "No certificate location specified"); - Assert.state(location.exists(), "Certificate location '" + location + "' does not exist"); + Assert.state(location.exists(), () -> "Certificate location '" + location + "' does not exist"); try (InputStream inputStream = location.getInputStream()) { return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(inputStream); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/AbstractTemplateViewResolverProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/AbstractTemplateViewResolverProperties.java index d152a393f6..b9422a539d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/AbstractTemplateViewResolverProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/AbstractTemplateViewResolverProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -152,7 +152,7 @@ public abstract class AbstractTemplateViewResolverProperties extends AbstractVie */ public void applyToMvcViewResolver(Object viewResolver) { Assert.isInstanceOf(AbstractTemplateViewResolver.class, viewResolver, - "ViewResolver is not an instance of AbstractTemplateViewResolver :" + viewResolver); + () -> "ViewResolver is not an instance of AbstractTemplateViewResolver :" + viewResolver); AbstractTemplateViewResolver resolver = (AbstractTemplateViewResolver) viewResolver; resolver.setPrefix(getPrefix()); resolver.setSuffix(getSuffix()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java index af88c06b66..8c9b5a573c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java @@ -168,7 +168,7 @@ public class UndertowWebServerFactoryCustomizer return (map) -> map.forEach((key, value) -> { Option option = (Option) this.nameLookup.get(getCanonicalName(key)); Assert.state(option != null, - "Unable to find '" + key + "' in " + ClassUtils.getShortClassName(this.source)); + () -> "Unable to find '" + key + "' in " + ClassUtils.getShortClassName(this.source)); T parsed = option.parseValue(value, getClass().getClassLoader()); function.apply(option).accept(parsed); }); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java index 777f01cb91..cf83dddd15 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java @@ -113,8 +113,8 @@ public class Builder { private void assertStackIdsMatch(Image runImage, Image builderImage) { StackId runImageStackId = StackId.fromImage(runImage); StackId builderImageStackId = StackId.fromImage(builderImage); - Assert.state(runImageStackId.equals(builderImageStackId), - "Run image stack '" + runImageStackId + "' does not match builder stack '" + builderImageStackId + "'"); + Assert.state(runImageStackId.equals(builderImageStackId), () -> "Run image stack '" + runImageStackId + + "' does not match builder stack '" + builderImageStackId + "'"); } private void executeLifecycle(BuildRequest request, EphemeralBuilder builder) throws IOException { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarModeLibrary.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarModeLibrary.java index 6664073164..acacd916c9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarModeLibrary.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/JarModeLibrary.java @@ -65,7 +65,7 @@ public class JarModeLibrary extends Library { public InputStream openStream() throws IOException { String path = "META-INF/jarmode/" + getCoordinates().getArtifactId() + ".jar"; URL resource = getClass().getClassLoader().getResource(path); - Assert.state(resource != null, "Unable to find resource " + path); + Assert.state(resource != null, () -> "Unable to find resource " + path); return resource.openStream(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java index a1b0641594..adc0d47a8c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java @@ -94,7 +94,7 @@ public abstract class Packager { protected Packager(File source, LayoutFactory layoutFactory) { Assert.notNull(source, "Source file must not be null"); Assert.isTrue(source.exists() && source.isFile(), - "Source must refer to an existing file, got " + source.getAbsolutePath()); + () -> "Source must refer to an existing file, got " + source.getAbsolutePath()); this.source = source.getAbsoluteFile(); this.layoutFactory = layoutFactory; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/CustomLayers.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/CustomLayers.java index 0d406d924e..c8334b5b16 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/CustomLayers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/layer/CustomLayers.java @@ -64,7 +64,7 @@ public class CustomLayers implements Layers { Layer layer = selector.getLayer(); Assert.state(layer != null, "Missing content selector layer"); Assert.state(layers.contains(layer), - "Content selector layer '" + selector.getLayer() + "' not found in " + layers); + () -> "Content selector layer '" + selector.getLayer() + "' not found in " + layers); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java index 0b5e823d0e..127e674294 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/LayersIndexTests.java @@ -130,7 +130,7 @@ class LayersIndexTests { String actualContent = getContent(); String name = "LayersIndexTests-" + LayersIndexTests.this.testMethodName + ".txt"; InputStream in = LayersIndexTests.class.getResourceAsStream(name); - Assert.state(in != null, "Can't read " + name); + Assert.state(in != null, () -> "Can't read " + name); String expectedContent = new String(FileCopyUtils.copyToByteArray(in), StandardCharsets.UTF_8); expectedContent = expectedContent.replace("\r", ""); assertThat(actualContent).isEqualTo(expectedContent); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java index bc5c964303..4adc7ddaee 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java @@ -105,7 +105,7 @@ class ConfigDataLoaders { } } } - Assert.state(result != null, "No loader found for location '" + location + "'"); + Assert.state(result != null, () -> "No loader found for location '" + location + "'"); return result; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializer.java index 8191f98d4f..5f0cf707a7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -92,7 +92,7 @@ public class DelegatingApplicationContextInitializer Class requireContextClass = GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class); Assert.isAssignable(requireContextClass, contextClass, - String.format( + () -> String.format( "Could not add context initializer [%s] as its generic parameter [%s] is not assignable " + "from the type of application context used by this context loader [%s]: ", initializerClass.getName(), requireContextClass.getName(), contextClass.getName())); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationListener.java index dd268efd10..6c693d5a18 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/DelegatingApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -81,7 +81,7 @@ public class DelegatingApplicationListener implements ApplicationListener clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader()); Assert.isAssignable(ApplicationListener.class, clazz, - "class [" + className + "] must implement ApplicationListener"); + () -> "class [" + className + "] must implement ApplicationListener"); listeners.add((ApplicationListener) BeanUtils.instantiateClass(clazz)); } catch (Exception ex) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java index 48b5061212..b5628a5f68 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -249,7 +249,7 @@ public final class ConfigurationPropertiesBean { static ConfigurationPropertiesBean forValueObject(Class beanClass, String beanName) { ConfigurationPropertiesBean propertiesBean = create(beanName, null, beanClass, null); Assert.state(propertiesBean != null && propertiesBean.getBindMethod() == BindMethod.VALUE_OBJECT, - "Bean '" + beanName + "' is not a @ConfigurationProperties value object"); + () -> "Bean '" + beanName + "' is not a @ConfigurationProperties value object"); return propertiesBean; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindConstructorProvider.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindConstructorProvider.java index 28c3b0412b..d9e4723c66 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindConstructorProvider.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindConstructorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -67,9 +67,9 @@ class ConfigurationPropertiesBindConstructorProvider implements BindConstructorP for (Constructor candidate : candidates) { if (MergedAnnotations.from(candidate).isPresent(ConstructorBinding.class)) { Assert.state(candidate.getParameterCount() > 0, - type.getName() + " declares @ConstructorBinding on a no-args constructor"); + () -> type.getName() + " declares @ConstructorBinding on a no-args constructor"); Assert.state(constructor == null, - type.getName() + " has more than one @ConstructorBinding constructor"); + () -> type.getName() + " has more than one @ConstructorBinding constructor"); constructor = candidate; } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/PeriodStyle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/PeriodStyle.java index 660e9501d1..2c968d0ca1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/PeriodStyle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/PeriodStyle.java @@ -48,7 +48,7 @@ public enum PeriodStyle { } Matcher matcher = matcher(value); Assert.state(matcher.matches(), "Does not match simple period pattern"); - Assert.isTrue(hasAtLeastOneGroupValue(matcher), "'" + value + "' is not a valid simple period"); + Assert.isTrue(hasAtLeastOneGroupValue(matcher), () -> "'" + value + "' is not a valid simple period"); int years = parseInt(matcher, 1); int months = parseInt(matcher, 2); int weeks = parseInt(matcher, 3); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java index b478c328b9..7bb667b5da 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/VolumeMountDirectoryPropertySource.java @@ -100,8 +100,8 @@ public class VolumeMountDirectoryPropertySource extends EnumerablePropertySource private VolumeMountDirectoryPropertySource(String name, Path sourceDirectory, Set