diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicator.java index 5057f80110f..e1b73a24101 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2025 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. @@ -69,7 +69,7 @@ public class AvailabilityStateHealthIndicator extends AbstractHealthIndicator { if (!this.statusMappings.containsKey(null) && Enum.class.isAssignableFrom(stateType)) { EnumSet elements = EnumSet.allOf((Class) stateType); for (Object element : elements) { - Assert.isTrue(this.statusMappings.containsKey(element), + Assert.state(this.statusMappings.containsKey(element), () -> "StatusMappings does not include " + element); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java index b120533b2db..820e345059a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/HeapDumpWebEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -209,7 +209,7 @@ public class HeapDumpWebEndpoint { @Override public File dumpHeap(Boolean live) throws IOException, InterruptedException { - Assert.isNull(live, "OpenJ9DiagnosticsMXBean does not support live parameter when dumping the heap"); + Assert.state(live == null, "OpenJ9DiagnosticsMXBean does not support live parameter when dumping the heap"); return new File( (String) ReflectionUtils.invokeMethod(this.dumpHeapMethod, this.diagnosticMXBean, "heap", null)); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicatorTests.java index a874e4be5f4..ea48c0a17cf 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -28,6 +28,7 @@ import org.springframework.boot.availability.LivenessState; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; /** @@ -67,7 +68,7 @@ class AvailabilityStateHealthIndicatorTests { @Test void createWhenStatusMappingDoesNotCoverAllEnumsThrowsException() { - assertThatIllegalArgumentException() + assertThatIllegalStateException() .isThrownBy(() -> new AvailabilityStateHealthIndicator(this.applicationAvailability, LivenessState.class, (statusMappings) -> statusMappings.add(LivenessState.CORRECT, Status.UP))) .withMessage("StatusMappings does not include BROKEN"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index e3da084cf8f..0eba73f1dd9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -57,6 +57,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** @@ -170,7 +171,7 @@ public class AutoConfigurationImportSelector implements DeferredImportSelector, protected AnnotationAttributes getAttributes(AnnotationMetadata metadata) { String name = getAnnotationClass().getName(); AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(name, true)); - Assert.notNull(attributes, () -> "No auto-configuration attributes found. Is " + metadata.getClassName() + Assert.state(attributes != null, () -> "No auto-configuration attributes found. Is " + metadata.getClassName() + " annotated with " + ClassUtils.getShortName(name) + "?"); return attributes; } @@ -195,7 +196,7 @@ public class AutoConfigurationImportSelector implements DeferredImportSelector, ImportCandidates importCandidates = ImportCandidates.load(this.autoConfigurationAnnotation, getBeanClassLoader()); List configurations = importCandidates.getCandidates(); - Assert.notEmpty(configurations, + Assert.state(!CollectionUtils.isEmpty(configurations), "No auto configuration classes found in " + "META-INF/spring/" + this.autoConfigurationAnnotation.getName() + ".imports. If you " + "are using a custom packaging, make sure that file is correct."); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java index a343346eb3e..1f66570f0d3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -112,10 +112,10 @@ public class JobLauncherApplicationRunner @Override public void afterPropertiesSet() { - Assert.isTrue(this.jobs.size() <= 1 || StringUtils.hasText(this.jobName), + Assert.state(this.jobs.size() <= 1 || StringUtils.hasText(this.jobName), "Job name must be specified in case of multiple jobs"); if (StringUtils.hasText(this.jobName)) { - Assert.isTrue(isLocalJob(this.jobName) || isRegisteredJob(this.jobName), + Assert.state(isLocalJob(this.jobName) || isRegisteredJob(this.jobName), () -> "No job found with name '" + this.jobName + "'"); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java index d41c4f43454..49d331a58f6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -102,7 +102,7 @@ public class CacheAutoConfiguration { @Override public void afterPropertiesSet() { - Assert.notNull(this.cacheManager.getIfAvailable(), + Assert.state(this.cacheManager.getIfAvailable() != null, () -> "No cache manager could be auto-configured, check your configuration (caching type is '" + this.cacheProperties.getType() + "')"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java index 25ef759f726..2c9c9229eb3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -250,8 +250,8 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat ConfigurableListableBeanFactory beanFactory = spec.getContext().getBeanFactory(); if (spec.getStrategy() == SearchStrategy.ANCESTORS) { BeanFactory parent = beanFactory.getParentBeanFactory(); - Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, - "Unable to use SearchStrategy.ANCESTORS"); + Assert.state(parent instanceof ConfigurableListableBeanFactory, + "Unable to use SearchStrategy.ANCESTORS without ConfigurableListableBeanFactory"); beanFactory = (ConfigurableListableBeanFactory) parent; } return beanFactory; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnResourceCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnResourceCondition.java index 16faa3ecb00..39ce2101cff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnResourceCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnResourceCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -45,7 +45,7 @@ class OnResourceCondition extends SpringBootCondition { ResourceLoader loader = context.getResourceLoader(); List locations = new ArrayList<>(); collectValues(locations, attributes.get("resources")); - Assert.isTrue(!locations.isEmpty(), + Assert.state(!locations.isEmpty(), "@ConditionalOnResource annotations must specify at least one resource location"); List missing = new ArrayList<>(); for (String location : locations) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 709418c2fe1..fb7313c773b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -583,7 +583,7 @@ public class FlywayAutoConfiguration { Extension(FluentConfiguration configuration, Class type, String name) { this.extension = SingletonSupplier.of(() -> { E extension = configuration.getPluginRegister().getPlugin(type); - Assert.notNull(extension, () -> "Flyway %s extension missing".formatted(name)); + Assert.state(extension != null, () -> "Flyway %s extension missing".formatted(name)); return extension; }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java index 524dbbaf9c1..4f88720d5b8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2025 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. @@ -52,7 +52,7 @@ public class HazelcastProperties { if (this.config == null) { return null; } - Assert.isTrue(this.config.exists(), + Assert.state(this.config.exists(), () -> "Hazelcast configuration does not exist '" + this.config.getDescription() + "'"); return this.config; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index 86242f258a5..cd21a090b39 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -292,7 +292,7 @@ public class JacksonAutoConfiguration { // Find the field (this way we automatically support new constants // that may be added by Jackson in the future) Field field = findPropertyNamingStrategyField(fieldName); - Assert.notNull(field, () -> "Constant named '" + fieldName + "' not found"); + Assert.state(field != null, () -> "Constant named '" + fieldName + "' not found"); try { builder.propertyNamingStrategy((PropertyNamingStrategy) field.get(null)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java index b78ec02c7f4..5eff8fadae9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -96,7 +96,8 @@ public class XADataSourceAutoConfiguration implements BeanClassLoaderAware { try { Class dataSourceClass = ClassUtils.forName(className, this.classLoader); Object instance = BeanUtils.instantiateClass(dataSourceClass); - Assert.isInstanceOf(XADataSource.class, instance); + Assert.state(instance instanceof XADataSource, + () -> "DataSource class " + className + " is not an XADataSource"); return (XADataSource) instance; } catch (Exception ex) { 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 aabed0af1bc..5eab4a231a3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -175,8 +175,8 @@ class Saml2RelyingPartyRegistrationConfiguration { try (InputStream inputStream = location.getInputStream()) { PemContent pemContent = PemContent.load(inputStream); PrivateKey privateKey = pemContent.getPrivateKey(); - Assert.isInstanceOf(RSAPrivateKey.class, privateKey, - "PrivateKey in resource '" + location + "' must be an RSAPrivateKey"); + Assert.state(privateKey instanceof RSAPrivateKey, + () -> "PrivateKey in resource '" + location + "' must be an RSAPrivateKey"); return (RSAPrivateKey) privateKey; } catch (Exception ex) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/CertificateMatcher.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/CertificateMatcher.java index 3f25ecc2c0c..c7b527b00f3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/CertificateMatcher.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/CertificateMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -53,7 +53,7 @@ class CertificateMatcher { Assert.notNull(privateKey, "Private key must not be null"); this.privateKey = privateKey; this.signature = createSignature(privateKey); - Assert.notNull(this.signature, "Failed to create signature"); + Assert.state(this.signature != null, "Failed to create signature"); this.generatedSignature = sign(this.signature, privateKey); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java index 1a8a35aa4e0..dc42c7ecb05 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ssl/PropertiesSslBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -127,7 +127,7 @@ public final class PropertiesSslBundle implements SslBundle { if (properties.isVerifyKeys()) { CertificateMatcher certificateMatcher = new CertificateMatcher(pemSslStore.privateKey()); Assert.state(certificateMatcher.matchesAny(pemSslStore.certificates()), - "Private key in %s matches none of the certificates in the chain".formatted(propertyName)); + () -> "Private key in %s matches none of the certificates in the chain".formatted(propertyName)); } return pemSslStore; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index 8f10bea4e03..b2a2b9100a8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -91,7 +91,7 @@ import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -484,7 +484,7 @@ class BatchAutoConfigurationTests { JobLauncherApplicationRunner runner = createInstance(); runner.setJobs(Arrays.asList(mockJob("one"), mockJob("two"))); runner.setJobName("three"); - assertThatIllegalArgumentException().isThrownBy(runner::afterPropertiesSet) + assertThatIllegalStateException().isThrownBy(runner::afterPropertiesSet) .withMessage("No job found with name 'three'"); } @@ -492,7 +492,7 @@ class BatchAutoConfigurationTests { void whenTheUserDefinesAJobNameThatDoesNotExistWithRegisteredJobFailsFast() { JobLauncherApplicationRunner runner = createInstance("one", "two"); runner.setJobName("three"); - assertThatIllegalArgumentException().isThrownBy(runner::afterPropertiesSet) + assertThatIllegalStateException().isThrownBy(runner::afterPropertiesSet) .withMessage("No job found with name 'three'"); } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 4d71ceddd12..7580d03e7e5 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -272,7 +272,7 @@ public class Restarter { } private Throwable doStart() throws Exception { - Assert.notNull(this.mainClassName, "Unable to find the main class to restart"); + Assert.state(this.mainClassName != null, "Unable to find the main class to restart"); URL[] urls = this.urls.toArray(new URL[0]); ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles); ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader, urls, updatedFiles); diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultConnectionPorts.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultConnectionPorts.java index 2981385ecb6..1b7999845c9 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultConnectionPorts.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultConnectionPorts.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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,8 @@ class DefaultConnectionPorts implements ConnectionPorts { @Override public int get(int containerPort) { Integer hostPort = this.portMappings.get(containerPort); - Assert.state(hostPort != null, "No host port mapping found for container port %s".formatted(containerPort)); + Assert.state(hostPort != null, + () -> "No host port mapping found for container port %s".formatted(containerPort)); return hostPort; } diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java index e50340605b1..612412b6779 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DefaultDockerCompose.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -102,7 +102,7 @@ class DefaultDockerCompose implements DockerCompose { Map inspected = inspect(runningPsResponses); for (DockerCliComposePsResponse psResponse : runningPsResponses) { DockerCliInspectResponse inspectResponse = inspectContainer(psResponse.id(), inspected); - Assert.notNull(inspectResponse, () -> "Failed to inspect container '%s'".formatted(psResponse.id())); + Assert.state(inspectResponse != null, () -> "Failed to inspect container '%s'".formatted(psResponse.id())); result.add(new DefaultRunningService(this.hostname, dockerComposeFile, psResponse, inspectResponse)); } return Collections.unmodifiableList(result); diff --git a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerComposeFile.java b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerComposeFile.java index 30156ed4c46..37382a7fbb4 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerComposeFile.java +++ b/spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerComposeFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -47,7 +47,7 @@ public final class DockerComposeFile { private final List files; private DockerComposeFile(List files) { - Assert.state(!files.isEmpty(), "Files must not be empty"); + Assert.isTrue(!files.isEmpty(), "'files' must not be empty"); this.files = files.stream().map(DockerComposeFile::toCanonicalFile).toList(); } @@ -112,7 +112,7 @@ public final class DockerComposeFile { if (!base.exists()) { return null; } - Assert.isTrue(base.isDirectory(), () -> "'%s' is not a directory".formatted(base)); + Assert.state(base.isDirectory(), () -> "'%s' is not a directory".formatted(base)); Path basePath = base.toPath(); for (String candidate : SEARCH_ORDER) { Path resolved = basePath.resolve(candidate); diff --git a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java index 95d3892d69e..dfd99833796 100644 --- a/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java +++ b/spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -27,6 +27,7 @@ import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link DockerComposeFile}. @@ -104,7 +105,7 @@ class DockerComposeFileTests { @Test void findWhenWorkingDirectoryIsNotDirectoryThrowsException() throws Exception { File file = createTempFile("iamafile"); - assertThatIllegalArgumentException().isThrownBy(() -> DockerComposeFile.find(file)) + assertThatIllegalStateException().isThrownBy(() -> DockerComposeFile.find(file)) .withMessageEndingWith("is not a directory"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpack.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpack.java index e649586e18b..aada48b018c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpack.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpack.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -65,7 +65,7 @@ class BuilderBuildpack implements Buildpack { .of(unambiguous ? reference.getSubReference(PREFIX) : reference.toString()); BuildpackMetadata buildpackMetadata = findBuildpackMetadata(context, builderReference); if (unambiguous) { - Assert.isTrue(buildpackMetadata != null, () -> "Buildpack '" + reference + "' not found in builder"); + Assert.state(buildpackMetadata != null, () -> "Buildpack '" + reference + "' not found in builder"); } return (buildpackMetadata != null) ? new BuilderBuildpack(buildpackMetadata) : null; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderMetadata.java index 831b524a3c8..3b566cbf0fb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -158,7 +158,7 @@ class BuilderMetadata extends MappedObject { static BuilderMetadata fromImageConfig(ImageConfig imageConfig) throws IOException { Assert.notNull(imageConfig, "ImageConfig must not be null"); String json = imageConfig.getLabels().get(LABEL_NAME); - Assert.notNull(json, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + Assert.state(json != null, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + StringUtils.collectionToCommaDelimitedString(imageConfig.getLabels().keySet()) + "'"); return fromJson(json); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java index 689729fa89c..093c93bc8ba 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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,7 @@ final class BuildpackLayersMetadata extends MappedObject { static BuildpackLayersMetadata fromImageConfig(ImageConfig imageConfig) throws IOException { Assert.notNull(imageConfig, "ImageConfig must not be null"); String json = imageConfig.getLabels().get(LABEL_NAME); - Assert.notNull(json, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + Assert.state(json != null, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + StringUtils.collectionToCommaDelimitedString(imageConfig.getLabels().keySet()) + "'"); return fromJson(json); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadata.java index 5b3d1e10986..f6d6b77213f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2025 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. @@ -94,7 +94,7 @@ final class BuildpackMetadata extends MappedObject { static BuildpackMetadata fromImageConfig(ImageConfig imageConfig) throws IOException { Assert.notNull(imageConfig, "ImageConfig must not be null"); String json = imageConfig.getLabels().get(LABEL_NAME); - Assert.notNull(json, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + Assert.state(json != null, () -> "No '" + LABEL_NAME + "' label found in image config labels '" + StringUtils.collectionToCommaDelimitedString(imageConfig.getLabels().keySet()) + "'"); return fromJson(json); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpack.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpack.java index bac39277e39..2ec5482a6f8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpack.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpack.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2025 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. @@ -56,7 +56,7 @@ final class DirectoryBuildpack implements Buildpack { private BuildpackCoordinates findBuildpackCoordinates(Path path) { Path buildpackToml = path.resolve("buildpack.toml"); - Assert.isTrue(Files.exists(buildpackToml), + Assert.state(Files.exists(buildpackToml), () -> "Buildpack descriptor 'buildpack.toml' is required in buildpack '" + path + "'"); try { try (InputStream inputStream = Files.newInputStream(buildpackToml)) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ExportedImageTar.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ExportedImageTar.java index f04cfef7fcd..1e20e3611e7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ExportedImageTar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ExportedImageTar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -127,7 +127,8 @@ class ExportedImageTar implements Closeable { entry = tar.getNextEntry(); } Assert.state(index != null || manifest != null, - "Exported image '%s' does not contain 'index.json' or 'manifest.json'".formatted(reference)); + () -> "Exported image '%s' does not contain 'index.json' or 'manifest.json'" + .formatted(reference)); return (index != null) ? new IndexLayerArchiveFactory(tarFile, index) : new ManifestLayerArchiveFactory(tarFile, manifest); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/PemPrivateKeyParser.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/PemPrivateKeyParser.java index 45e4e5c9b47..9f1275eea3b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/PemPrivateKeyParser.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/ssl/PemPrivateKeyParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -445,7 +445,7 @@ final class PemPrivateKeyParser { public static final String PBES2_ALGORITHM = "PBES2"; static PKCS8EncodedKeySpec decrypt(byte[] bytes, String password) { - Assert.notNull(password, "Password is required for an encrypted private key"); + Assert.state(password != null, "Password is required for an encrypted private key"); try { EncryptedPrivateKeyInfo keyInfo = new EncryptedPrivateKeyInfo(bytes); AlgorithmParameters algorithmParameters = keyInfo.getAlgParameters(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java index 1b8d84260d8..6eed8043bb7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -35,6 +35,7 @@ import org.springframework.boot.buildpack.platform.docker.configuration.DockerHo import org.springframework.boot.buildpack.platform.docker.configuration.ResolvedDockerHost; import org.springframework.boot.buildpack.platform.docker.ssl.SslContextFactory; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * {@link HttpClientTransport} that talks to a remote Docker. @@ -85,8 +86,8 @@ final class RemoteHttpClientTransport extends HttpClientTransport { private static TlsSocketStrategy getTlsSocketStrategy(DockerHost host, SslContextFactory sslContextFactory) { String directory = host.getCertificatePath(); - Assert.hasText(directory, - () -> "Docker host TLS verification requires trust material location to be specified with certificate path"); + Assert.state(StringUtils.hasText(directory), + "Docker host TLS verification requires trust material location to be specified with certificate path"); SSLContext sslContext = sslContextFactory.forDirectory(directory); return new DefaultClientTlsStrategy(sslContext); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java index d19666afdbf..d3966a0ccb4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -27,7 +27,7 @@ import org.springframework.boot.buildpack.platform.docker.type.Layer; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -86,7 +86,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { @Test void resolveWhenFullyQualifiedBuildpackWithVersionNotInBuilderThrowsException() { BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack1@1.2.3"); - assertThatIllegalArgumentException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference)) + assertThatIllegalStateException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference)) .withMessageContaining("'urn:cnb:builder:example/buildpack1@1.2.3'") .withMessageContaining("not found in builder"); } @@ -94,7 +94,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { @Test void resolveWhenFullyQualifiedBuildpackWithoutVersionNotInBuilderThrowsException() { BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack1"); - assertThatIllegalArgumentException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference)) + assertThatIllegalStateException().isThrownBy(() -> BuilderBuildpack.resolve(this.resolverContext, reference)) .withMessageContaining("'urn:cnb:builder:example/buildpack1'") .withMessageContaining("not found in builder"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java index fd6803401d7..292df537fdc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -28,6 +28,7 @@ import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -105,7 +106,7 @@ class BuilderMetadataTests extends AbstractJsonTests { ImageConfig imageConfig = mock(ImageConfig.class); given(image.getConfig()).willReturn(imageConfig); given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a")); - assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(image)) + assertThatIllegalStateException().isThrownBy(() -> BuilderMetadata.fromImage(image)) .withMessage("No 'io.buildpacks.builder.metadata' label found in image config labels 'alpha'"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java index 239143aa477..22c7b57e2ab 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -517,7 +517,7 @@ class BuilderTests { Builder builder = new Builder(BuildLog.to(out), docker, null); BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:example/buildpack@1.2.3"); BuildRequest request = getTestRequest().withBuildpacks(reference); - assertThatIllegalArgumentException().isThrownBy(() -> builder.build(request)) + assertThatIllegalStateException().isThrownBy(() -> builder.build(request)) .withMessageContaining("'urn:cnb:builder:example/buildpack@1.2.3'") .withMessageContaining("not found in builder"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java index 31d692f849a..83fdc112263 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -27,6 +27,7 @@ import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -70,7 +71,7 @@ class BuildpackLayersMetadataTests extends AbstractJsonTests { ImageConfig imageConfig = mock(ImageConfig.class); given(image.getConfig()).willReturn(imageConfig); given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a")); - assertThatIllegalArgumentException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(image)) + assertThatIllegalStateException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(image)) .withMessage("No 'io.buildpacks.buildpack.layers' label found in image config labels 'alpha'"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java index dd9fac9d1ae..6ca36bcdd1f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -27,6 +27,7 @@ import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -64,7 +65,7 @@ class BuildpackMetadataTests extends AbstractJsonTests { ImageConfig imageConfig = mock(ImageConfig.class); given(image.getConfig()).willReturn(imageConfig); given(imageConfig.getLabels()).willReturn(Collections.singletonMap("alpha", "a")); - assertThatIllegalArgumentException().isThrownBy(() -> BuildpackMetadata.fromImage(image)) + assertThatIllegalStateException().isThrownBy(() -> BuildpackMetadata.fromImage(image)) .withMessage("No 'io.buildpacks.buildpackage.metadata' label found in image config labels 'alpha'"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java index 3fdbd121859..aae2015c578 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -37,7 +37,7 @@ import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.io.TempDir; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; @@ -89,8 +89,7 @@ class DirectoryBuildpackTests { void resolveWhenDirectoryWithoutBuildpackTomlThrowsException() throws Exception { Files.createDirectories(this.buildpackDir.toPath()); BuildpackReference reference = BuildpackReference.of(this.buildpackDir.toString()); - assertThatIllegalArgumentException() - .isThrownBy(() -> DirectoryBuildpack.resolve(this.resolverContext, reference)) + assertThatIllegalStateException().isThrownBy(() -> DirectoryBuildpack.resolve(this.resolverContext, reference)) .withMessageContaining("Buildpack descriptor 'buildpack.toml' is required") .withMessageContaining(this.buildpackDir.getAbsolutePath()); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java index 4385e419300..2c91342e351 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -43,6 +43,7 @@ import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.any; @@ -156,7 +157,7 @@ class ImageBuildpackTests extends AbstractJsonTests { BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class); given(resolverContext.fetchImage(any(), any())).willReturn(image); BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:latest"); - assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference)) + assertThatIllegalStateException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference)) .withMessageContaining("No 'io.buildpacks.buildpackage.metadata' label found"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java index 529709d5cc3..87767ed49ac 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -28,7 +28,7 @@ import org.springframework.boot.buildpack.platform.docker.configuration.Resolved import org.springframework.boot.buildpack.platform.docker.ssl.SslContextFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -92,7 +92,7 @@ class RemoteHttpClientTransportTests { void createIfPossibleWhenTlsVerifyWithMissingCertPathThrowsException() { ResolvedDockerHost dockerHost = ResolvedDockerHost .from(DockerHostConfiguration.forAddress("tcp://192.168.1.2:2376", true, null)); - assertThatIllegalArgumentException().isThrownBy(() -> RemoteHttpClientTransport.createIfPossible(dockerHost)) + assertThatIllegalStateException().isThrownBy(() -> RemoteHttpClientTransport.createIfPossible(dockerHost)) .withMessageContaining("Docker host TLS verification requires trust material"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java index 557c44304d7..0e20291d33e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/InitCommand.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -220,7 +220,7 @@ public class InitCommand extends OptionParsingCommand { protected ProjectGenerationRequest createProjectGenerationRequest(OptionSet options) { List nonOptionArguments = new ArrayList(options.nonOptionArguments()); - Assert.isTrue(nonOptionArguments.size() <= 1, "Only the target location may be specified"); + Assert.state(nonOptionArguments.size() <= 1, "Only the target location may be specified"); ProjectGenerationRequest request = new ProjectGenerationRequest(); request.setServiceUrl(options.valueOf(this.target)); if (options.has(this.bootVersion)) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedJarStructure.java b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedJarStructure.java index 855160ba1c6..a50c18ec333 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedJarStructure.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedJarStructure.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -128,13 +128,13 @@ class IndexedJarStructure implements JarStructure { } private String toStructureDependency(String libEntryName) { - Assert.state(libEntryName.startsWith(this.libLocation), "Invalid library location " + libEntryName); + Assert.state(libEntryName.startsWith(this.libLocation), () -> "Invalid library location " + libEntryName); return libEntryName.substring(this.libLocation.length()); } private static String getMandatoryAttribute(Manifest manifest, String attribute) { String value = manifest.getMainAttributes().getValue(attribute); - Assert.state(value != null, "Manifest attribute '" + attribute + "' is mandatory"); + Assert.state(value != null, () -> "Manifest attribute '" + attribute + "' is mandatory"); return value; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedLayers.java b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedLayers.java index 0469aeed836..2de7e22fce5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedLayers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/IndexedLayers.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -60,7 +60,7 @@ class IndexedLayers implements Layers { this.layers.put(line.substring(3, line.length() - 2), contents); } else if (line.startsWith(" - ")) { - Assert.notNull(contents, "Contents must not be null. Check if the index file is malformed!"); + Assert.state(contents != null, "Contents must not be null. Check if the index file is malformed!"); contents.add(line.substring(5, line.length() - 1)); } else { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertyMigration.java b/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertyMigration.java index 933adf52121..61a5223e57c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertyMigration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertyMigration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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,7 @@ class PropertyMigration { ConfigurationPropertyName oldName = property.getName(); ConfigurationPropertyName oldPrefix = ConfigurationPropertyName.of(metadata.getId()); Assert.state(oldPrefix.isAncestorOf(oldName), - String.format("'%s' is not an ancestor of '%s'", oldPrefix, oldName)); + () -> "'%s' is not an ancestor of '%s'".formatted(oldPrefix, oldName)); ConfigurationPropertyName newPrefix = ConfigurationPropertyName.of(replacement.getId()); return newPrefix.append(oldName.subName(oldPrefix.getNumberOfElements())); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/process/DisabledIfProcessUnavailableCondition.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/process/DisabledIfProcessUnavailableCondition.java index 61212465997..2b543413971 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/process/DisabledIfProcessUnavailableCondition.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/process/DisabledIfProcessUnavailableCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -69,7 +69,7 @@ class DisabledIfProcessUnavailableCondition implements ExecutionCondition { ProcessBuilder processBuilder = new ProcessBuilder(command); try { Process process = processBuilder.start(); - Assert.isTrue(process.waitFor(30, TimeUnit.SECONDS), "Process did not exit within 30 seconds"); + Assert.state(process.waitFor(30, TimeUnit.SECONDS), "Process did not exit within 30 seconds"); Assert.state(process.exitValue() == 0, () -> "Process exited with %d".formatted(process.exitValue())); process.destroy(); } 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 e1d311ff765..4a673a37821 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -410,7 +410,7 @@ public class SpringApplication { if (!AotDetector.useGeneratedArtifacts()) { // Load the sources Set sources = getAllSources(); - Assert.notEmpty(sources, "Sources must not be empty"); + Assert.state(!ObjectUtils.isEmpty(sources), "No sources defined"); load(context, sources.toArray(new Object[0])); } listeners.contextLoaded(context); @@ -608,7 +608,7 @@ public class SpringApplication { for (ApplicationContextInitializer initializer : getInitializers()) { Class requiredType = GenericTypeResolver.resolveTypeArgument(initializer.getClass(), ApplicationContextInitializer.class); - Assert.isInstanceOf(requiredType, context, "Unable to call initializer."); + Assert.state(requiredType.isInstance(context), "Unable to call initializer"); initializer.initialize(context); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationAotProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationAotProcessor.java index bfc94d22620..448eb9c3ef1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationAotProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationAotProcessor.java @@ -65,7 +65,7 @@ public class SpringApplicationAotProcessor extends ContextAotProcessor { public static void main(String[] args) throws Exception { int requiredArgs = 6; - Assert.isTrue(args.length >= requiredArgs, () -> "Usage: " + SpringApplicationAotProcessor.class.getName() + Assert.state(args.length >= requiredArgs, () -> "Usage: " + SpringApplicationAotProcessor.class.getName() + " "); Class application = Class.forName(args[0]); Settings settings = Settings.builder() @@ -110,7 +110,7 @@ public class SpringApplicationAotProcessor extends ContextAotProcessor { } catch (AbandonedRunException ex) { ApplicationContext context = ex.getApplicationContext(); - Assert.isInstanceOf(GenericApplicationContext.class, context, + Assert.state(context instanceof GenericApplicationContext, () -> "AOT processing requires a GenericApplicationContext but got a " + context.getClass().getName()); return (GenericApplicationContext) context; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java index 156e4a6c03d..5ed87c79520 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigTreeConfigDataLocationResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2025 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. @@ -60,7 +60,7 @@ public class ConfigTreeConfigDataLocationResolver implements ConfigDataLocationR } private List resolve(String location) throws IOException { - Assert.isTrue(location.endsWith("/"), + Assert.state(location.endsWith("/"), () -> String.format("Config tree location '%s' must end with '/'", location)); if (!this.resourceLoader.isPattern(location)) { return Collections.singletonList(new ConfigTreeConfigDataResource(location)); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartup.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartup.java index 33b4ab0fcb1..99639fe781f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartup.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartup.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 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. @@ -91,7 +91,7 @@ public class BufferingApplicationStartup implements ApplicationStartup { * already. */ public void startRecording() { - Assert.state(this.events.isEmpty(), "Cannot restart recording once steps have been buffered."); + Assert.state(this.events.isEmpty(), "Cannot restart recording once steps have been buffered"); this.startTime = this.clock.instant(); } 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 ea43e8b7b04..cc5319c4ac1 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -264,7 +264,7 @@ public enum PeriodStyle { } private int intValue(Period value) { - Assert.notNull(this.intValue, () -> "intValue cannot be extracted from " + name()); + Assert.state(this.intValue != null, () -> "intValue cannot be extracted from " + name()); return this.intValue.apply(value); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java index b01f16fb3d6..47911d44650 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -195,11 +195,11 @@ public class RandomValuePropertySource extends PropertySource { String[] tokens = StringUtils.commaDelimitedListToStringArray(value); T min = parse.apply(tokens[0]); if (tokens.length == 1) { - Assert.isTrue(min.compareTo(zero) > 0, "Bound must be positive."); + Assert.state(min.compareTo(zero) > 0, "Bound must be positive."); return new Range<>(value, zero, min); } T max = parse.apply(tokens[1]); - Assert.isTrue(min.compareTo(max) < 0, "Lower bound must be less than upper bound."); + Assert.state(min.compareTo(max) < 0, "Lower bound must be less than upper bound."); return new Range<>(value, min, max); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/HikariCheckpointRestoreLifecycle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/HikariCheckpointRestoreLifecycle.java index bf5ae8478a8..fc529c0bc0c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/HikariCheckpointRestoreLifecycle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/HikariCheckpointRestoreLifecycle.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -61,9 +61,9 @@ public class HikariCheckpointRestoreLifecycle implements Lifecycle { static { Field closeConnectionExecutor = ReflectionUtils.findField(HikariPool.class, "closeConnectionExecutor"); - Assert.notNull(closeConnectionExecutor, "Unable to locate closeConnectionExecutor for HikariPool"); - Assert.isAssignable(ThreadPoolExecutor.class, closeConnectionExecutor.getType(), - "Expected ThreadPoolExecutor for closeConnectionExecutor but found %s" + Assert.state(closeConnectionExecutor != null, "Unable to locate closeConnectionExecutor for HikariPool"); + Assert.state(ThreadPoolExecutor.class.isAssignableFrom(closeConnectionExecutor.getType()), + () -> "Expected ThreadPoolExecutor for closeConnectionExecutor but found %s" .formatted(closeConnectionExecutor.getType())); ReflectionUtils.makeAccessible(closeConnectionExecutor); CLOSE_CONNECTION_EXECUTOR = closeConnectionExecutor; @@ -104,7 +104,7 @@ public class HikariCheckpointRestoreLifecycle implements Lifecycle { this.hasOpenConnections = (pool) -> { ThreadPoolExecutor closeConnectionExecutor = (ThreadPoolExecutor) ReflectionUtils .getField(CLOSE_CONNECTION_EXECUTOR, pool); - Assert.notNull(closeConnectionExecutor, "CloseConnectionExecutor was null"); + Assert.state(closeConnectionExecutor != null, "'closeConnectionExecutor' was null"); return closeConnectionExecutor.getActiveCount() > 0; }; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java index dbd8237aebd..7e924ce2340 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -184,7 +184,7 @@ class JsonValueWriter { void writeElement(E element) { ActiveSeries activeSeries = this.activeSeries.peek(); - Assert.notNull(activeSeries, "No series has been started"); + Assert.state(activeSeries != null, "No series has been started"); this.path = activeSeries.updatePath(this.path); activeSeries.incrementIndexAndAddCommaIfRequired(); write(element); @@ -223,7 +223,7 @@ class JsonValueWriter { if (!isFilteredPath()) { String processedName = processName(name.toString()); ActiveSeries activeSeries = this.activeSeries.peek(); - Assert.notNull(activeSeries, "No series has been started"); + Assert.state(activeSeries != null, "No series has been started"); activeSeries.incrementIndexAndAddCommaIfRequired(); Assert.state(activeSeries.addName(processedName), () -> "The name '" + processedName + "' has already been written"); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggerConfiguration.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggerConfiguration.java index c1f67d81ea7..e472bee11ef 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggerConfiguration.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LoggerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -190,7 +190,7 @@ public final class LoggerConfiguration { * @throws IllegalStateException if this is a {@link #isCustom() custom} level */ public LogLevel getLevel() { - Assert.state(this.logLevel != null, "Unable to provide LogLevel for '" + this.name + "'"); + Assert.state(this.logLevel != null, () -> "Unable to provide LogLevel for '" + this.name + "'"); return this.logLevel; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index e30da9139bf..c5e6d891ac7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -409,7 +409,7 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF private LoggerContext getLoggerContext() { ILoggerFactory factory = getLoggerFactory(); - Assert.isInstanceOf(LoggerContext.class, factory, + Assert.state(factory instanceof LoggerContext, () -> String.format( "LoggerFactory is not a Logback LoggerContext but Logback is on " + "the classpath. Either remove Logback or the competing " diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactory.java index 22e3c6d872c..a508d1ae05e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -147,7 +147,7 @@ public class StructuredLogFormatterFactory { private void checkTypeArgument(Object formatter) { Class typeArgument = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), StructuredLogFormatter.class); - Assert.isTrue(this.logEventType.equals(typeArgument), + Assert.state(this.logEventType.equals(typeArgument), () -> "Type argument of %s must be %s but was %s".formatted(formatter.getClass().getName(), this.logEventType.getName(), (typeArgument != null) ? typeArgument.getName() : "null")); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java index 85161bbfbc7..3d41fca177c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnection.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2025 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. @@ -99,7 +99,7 @@ public enum EmbeddedDatabaseConnection { */ public static boolean isEmbedded(ConnectionFactory connectionFactory) { OptionsCapableConnectionFactory optionsCapable = OptionsCapableConnectionFactory.unwrapFrom(connectionFactory); - Assert.notNull(optionsCapable, + Assert.state(optionsCapable != null, () -> "Cannot determine database's type as ConnectionFactory is not options-capable. To be " + "options-capable, a ConnectionFactory should be created with " + ConnectionFactoryBuilder.class.getName()); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemPrivateKeyParser.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemPrivateKeyParser.java index 72e65d7c282..cc42ad117b3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemPrivateKeyParser.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemPrivateKeyParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -445,7 +445,7 @@ final class PemPrivateKeyParser { public static final String PBES2_ALGORITHM = "PBES2"; static PKCS8EncodedKeySpec decrypt(byte[] bytes, String password) { - Assert.notNull(password, "Password is required for an encrypted private key"); + Assert.state(password != null, "Password is required for an encrypted private key"); try { EncryptedPrivateKeyInfo keyInfo = new EncryptedPrivateKeyInfo(bytes); AlgorithmParameters algorithmParameters = keyInfo.getAlgParameters(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreBundle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreBundle.java index 6bb2d37ab24..3e1aac5f0e8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreBundle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreBundle.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -29,6 +29,7 @@ import java.util.function.Supplier; import org.springframework.boot.ssl.SslStoreBundle; import org.springframework.core.style.ToStringCreator; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.util.function.SingletonSupplier; @@ -89,7 +90,7 @@ public class PemSslStoreBundle implements SslStoreBundle { } try { List certificates = pemSslStore.certificates(); - Assert.notEmpty(certificates, "Certificates must not be empty"); + Assert.state(!ObjectUtils.isEmpty(certificates), "Certificates must not be empty"); String alias = (pemSslStore.alias() != null) ? pemSslStore.alias() : DEFAULT_ALIAS; KeyStore store = createKeyStore(pemSslStore.type()); PrivateKey privateKey = pemSslStore.privateKey(); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/Instantiator.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/Instantiator.java index 87d2d300d43..593c607600f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/Instantiator.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/Instantiator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -182,7 +182,7 @@ public class Instantiator { public A getArg(Class type) { Assert.notNull(type, "'type' must not be null"); Function, Object> parameter = getAvailableParameter(type); - Assert.isTrue(parameter != null, "Unknown argument type " + type.getName()); + Assert.state(parameter != null, "Unknown argument type " + type.getName()); return (A) parameter.apply(this.type); } @@ -193,7 +193,7 @@ public class Instantiator { private T instantiate(TypeSupplier typeSupplier) { try { Class type = typeSupplier.get(); - Assert.isAssignable(this.type, type); + Assert.state(this.type.isAssignableFrom(type), () -> type + " is not assignable to " + this.type); return instantiate(type); } catch (Throwable ex) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java index 87f8ba2fd32..d421df46474 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -162,7 +162,7 @@ public class NettyWebServer implements WebServer { } if (this.resourceFactory != null) { LoopResources resources = this.resourceFactory.getLoopResources(); - Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); + Assert.state(resources != null, "No LoopResources: is ReactorResourceFactory not initialized yet?"); server = server.runOn(resources); } if (this.lifecycleTimeout != null) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java index 32e3997ff4e..eb54a5883da 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -175,7 +175,7 @@ public class UndertowWebServer implements WebServer { this.closeables.add(closeable); } if (handler instanceof GracefulShutdownHandler shutdownHandler) { - Assert.isNull(this.gracefulShutdown, "Only a single GracefulShutdownHandler can be defined"); + Assert.state(this.gracefulShutdown == null, "Only a single GracefulShutdownHandler can be defined"); this.gracefulShutdown = shutdownHandler; } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/DelegatingFilterProxyRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/DelegatingFilterProxyRegistrationBean.java index 08aacb27077..883366e9094 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/DelegatingFilterProxyRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/DelegatingFilterProxyRegistrationBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -95,8 +95,9 @@ public class DelegatingFilterProxyRegistrationBean extends AbstractFilterRegistr } private WebApplicationContext getWebApplicationContext() { - Assert.notNull(this.applicationContext, "ApplicationContext be injected"); - Assert.isInstanceOf(WebApplicationContext.class, this.applicationContext); + Assert.state(this.applicationContext != null, "ApplicationContext has not been injected"); + Assert.state(this.applicationContext instanceof WebApplicationContext, + "Injected ApplicationContext is not a WebApplicationContext"); return (WebApplicationContext) this.applicationContext; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentHandler.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentHandler.java index ace35a20c83..5f0e6ad55c8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentHandler.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -52,7 +52,7 @@ abstract class ServletComponentHandler { String[] value = (String[]) attributes.get("value"); String[] urlPatterns = (String[]) attributes.get("urlPatterns"); if (urlPatterns.length > 0) { - Assert.state(value.length == 0, "The urlPatterns and value attributes are mutually exclusive."); + Assert.state(value.length == 0, "The urlPatterns and value attributes are mutually exclusive"); return urlPatterns; } return value; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java index 6d6b08a691b..5698aa47d4d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2025 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. @@ -168,7 +168,7 @@ public class ServletRegistrationBean extends DynamicRegistrat @Override protected String getDescription() { - Assert.notNull(this.servlet, "Servlet must not be null"); + Assert.state(this.servlet != null, "Unable to return description for null servlet"); return "servlet " + getServletName(); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java index 24b9f9f7301..2db0367d385 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2025 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. @@ -30,7 +30,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link SpringApplication} main method. @@ -45,7 +45,7 @@ class SimpleMainTests { @Test void emptyApplicationContext() { - assertThatIllegalArgumentException().isThrownBy(() -> SpringApplication.main(getArgs())); + assertThatIllegalStateException().isThrownBy(() -> SpringApplication.main(getArgs())); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationAotProcessorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationAotProcessorTests.java index 4894e275840..86fba06c78d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationAotProcessorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationAotProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -26,7 +26,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.aot.AbstractAotProcessor.Settings; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** @@ -84,8 +83,7 @@ class SpringApplicationAotProcessorTests { @Test void invokeMainWithMissingArguments() { - assertThatIllegalArgumentException() - .isThrownBy(() -> SpringApplicationAotProcessor.main(new String[] { "Test" })) + assertThatIllegalStateException().isThrownBy(() -> SpringApplicationAotProcessor.main(new String[] { "Test" })) .withMessageContaining("Usage:"); } 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 ccd17f15ae3..56f699bb4b8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -213,8 +213,8 @@ class SpringApplicationTests { @Test void sourcesMustNotBeEmpty() { - assertThatIllegalArgumentException().isThrownBy(() -> new SpringApplication().run()) - .withMessageContaining("Sources must not be empty"); + assertThatIllegalStateException().isThrownBy(() -> new SpringApplication().run()) + .withMessageContaining("No sources defined"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartupTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartupTests.java index d146f475071..ed891a417dd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartupTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/metrics/buffering/BufferingApplicationStartupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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,7 +88,7 @@ class BufferingApplicationStartupTests { BufferingApplicationStartup applicationStartup = new BufferingApplicationStartup(2); applicationStartup.start("first").end(); assertThatIllegalStateException().isThrownBy(applicationStartup::startRecording) - .withMessage("Cannot restart recording once steps have been buffered."); + .withMessage("Cannot restart recording once steps have been buffered"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java index 1fb9ad176d8..8c3c4bd620b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -28,7 +28,7 @@ import org.springframework.core.env.SystemEnvironmentPropertySource; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.spy; @@ -76,7 +76,7 @@ class RandomValuePropertySourceTests { @Test void intRangeWhenLowerBoundEqualsUpperBoundShouldFailWithIllegalArgumentException() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.int[4,4]")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.int[4,4]")) .withMessage("Lower bound must be less than upper bound."); } @@ -95,13 +95,13 @@ class RandomValuePropertySourceTests { @Test void intMaxZero() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.int(0)")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.int(0)")) .withMessage("Bound must be positive."); } @Test void intNegativeBound() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.int(-5)")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.int(-5)")) .withMessage("Bound must be positive."); } @@ -119,7 +119,7 @@ class RandomValuePropertySourceTests { @Test void longRangeWhenLowerBoundEqualsUpperBoundShouldFailWithIllegalArgumentException() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.long[4,4]")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.long[4,4]")) .withMessage("Lower bound must be less than upper bound."); } @@ -138,13 +138,13 @@ class RandomValuePropertySourceTests { @Test void longMaxZero() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.long(0)")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.long(0)")) .withMessage("Bound must be positive."); } @Test void longNegativeBound() { - assertThatIllegalArgumentException().isThrownBy(() -> this.source.getProperty("random.long(-5)")) + assertThatIllegalStateException().isThrownBy(() -> this.source.getProperty("random.long(-5)")) .withMessage("Bound must be positive."); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/StructuredLoggingLayoutTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/StructuredLoggingLayoutTests.java index cf688e167d7..9e9d65ea0e8 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/StructuredLoggingLayoutTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/StructuredLoggingLayoutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -33,6 +33,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link StructuredLogLayout}. @@ -93,14 +94,14 @@ class StructuredLoggingLayoutTests extends AbstractStructuredLoggingTests { @Test void shouldCheckTypeArgument() { - assertThatIllegalArgumentException().isThrownBy( + assertThatIllegalStateException().isThrownBy( () -> newBuilder().setFormat(CustomLog4j2StructuredLoggingFormatterWrongType.class.getName()).build()) .withMessageContaining("must be org.apache.logging.log4j.core.LogEvent but was java.lang.String"); } @Test void shouldCheckTypeArgumentWithRawType() { - assertThatIllegalArgumentException() + assertThatIllegalStateException() .isThrownBy( () -> newBuilder().setFormat(CustomLog4j2StructuredLoggingFormatterRawType.class.getName()).build()) .withMessageContaining("must be org.apache.logging.log4j.core.LogEvent but was null"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/StructuredLogEncoderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/StructuredLogEncoderTests.java index f24543c9235..eb52d08dab2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/StructuredLogEncoderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/StructuredLogEncoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -35,6 +35,7 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link StructuredLogEncoder}. @@ -113,7 +114,7 @@ class StructuredLogEncoderTests extends AbstractStructuredLoggingTests { @Test void shouldCheckTypeArgument() { - assertThatIllegalArgumentException().isThrownBy(() -> { + assertThatIllegalStateException().isThrownBy(() -> { this.encoder.setFormat(CustomLogbackStructuredLoggingFormatterWrongType.class.getName()); this.encoder.start(); }).withMessageContaining("must be ch.qos.logback.classic.spi.ILoggingEvent but was java.lang.String"); @@ -121,7 +122,7 @@ class StructuredLogEncoderTests extends AbstractStructuredLoggingTests { @Test void shouldCheckTypeArgumentWithRawType() { - assertThatIllegalArgumentException().isThrownBy(() -> { + assertThatIllegalStateException().isThrownBy(() -> { this.encoder.setFormat(CustomLogbackStructuredLoggingFormatterRawType.class.getName()); this.encoder.start(); }).withMessageContaining("must be ch.qos.logback.classic.spi.ILoggingEvent but was null"); @@ -133,8 +134,8 @@ class StructuredLogEncoderTests extends AbstractStructuredLoggingTests { this.encoder.setFormat("does-not-exist"); this.encoder.start(); }) - .withMessageContaining( - "Unknown format 'does-not-exist'. Values can be a valid fully-qualified class name or one of the common formats: [ecs, gelf, logstash]"); + .withMessageContaining("Unknown format 'does-not-exist'. Values can be a valid fully-qualified " + + "class name or one of the common formats: [ecs, gelf, logstash]"); } private String encode(LoggingEvent event) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactoryTests.java index cc0bbc8d043..db8b5da3fee 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -31,6 +31,7 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -83,7 +84,7 @@ class StructuredLogFormatterFactoryTests { @Test void getUsingClassNameWhenHasGenericMismatch() { - assertThatIllegalArgumentException().isThrownBy(() -> this.factory.get(DifferentFormatter.class.getName())) + assertThatIllegalStateException().isThrownBy(() -> this.factory.get(DifferentFormatter.class.getName())) .withMessage("Type argument of org.springframework.boot.logging.structured." + "StructuredLogFormatterFactoryTests$DifferentFormatter " + "must be org.springframework.boot.logging.structured." diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java index 57433751adc..c9e17c9862d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/EmbeddedDatabaseConnectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -29,7 +29,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; /** * Tests for {@link EmbeddedDatabaseConnection}. @@ -85,7 +85,7 @@ class EmbeddedDatabaseConnectionTests { @Test void whenConnectionFactoryIsNotOptionsCapableThenIsEmbeddedThrows() { - assertThatIllegalArgumentException() + assertThatIllegalStateException() .isThrownBy(() -> EmbeddedDatabaseConnection .isEmbedded(ConnectionFactories.get("r2dbc:pool:h2:mem:///" + UUID.randomUUID()))) .withMessage("Cannot determine database's type as ConnectionFactory is not options-capable. To be " diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java index dba42d456c8..c7e2deec9df 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/InstantiatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -140,7 +140,7 @@ class InstantiatorTests { @Test void getArgWhenUnknownThrowsException() { Instantiator instantiator = createInstantiator(WithMultipleConstructors.class); - assertThatIllegalArgumentException().isThrownBy(() -> instantiator.getArg(InputStream.class)) + assertThatIllegalStateException().isThrownBy(() -> instantiator.getArg(InputStream.class)) .withMessageStartingWith("Unknown argument type"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java index ffe321d8087..f36443b40f0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -135,8 +135,8 @@ class ServletRegistrationBeanTests { @Test void setServletMustNotBeNull() { ServletRegistrationBean bean = new ServletRegistrationBean<>(); - assertThatIllegalArgumentException().isThrownBy(() -> bean.onStartup(this.servletContext)) - .withMessageContaining("Servlet must not be null"); + assertThatIllegalStateException().isThrownBy(() -> bean.onStartup(this.servletContext)) + .withMessageContaining("Unable to return description for null servlet"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebFilterHandlerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebFilterHandlerTests.java index 7661634cd15..d797f1fab49 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebFilterHandlerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebFilterHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -130,7 +130,7 @@ class WebFilterHandlerTests { void urlPatternsDeclaredTwice() { assertThatIllegalStateException() .isThrownBy(() -> handleBeanDefinitionForClass(UrlPatternsDeclaredTwiceFilter.class)) - .withMessageContaining("The urlPatterns and value attributes are mutually exclusive."); + .withMessageContaining("The urlPatterns and value attributes are mutually exclusive"); } private AnnotatedBeanDefinition createBeanDefinition(Class filterClass) throws IOException { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebServletHandlerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebServletHandlerTests.java index 660713a5e38..4bfee967d78 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebServletHandlerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/WebServletHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2025 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. @@ -105,7 +105,7 @@ class WebServletHandlerTests { void urlPatternsDeclaredTwice() { assertThatIllegalStateException() .isThrownBy(() -> handleBeanDefinitionForClass(UrlPatternsDeclaredTwiceServlet.class)) - .withMessageContaining("The urlPatterns and value attributes are mutually exclusive."); + .withMessageContaining("The urlPatterns and value attributes are mutually exclusive"); } private AnnotatedBeanDefinition createBeanDefinition(Class servletClass) throws IOException { diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java index e1f8086e928..9e2630adaf2 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/junit/GradleBuildInjectionExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2025 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. @@ -40,7 +40,7 @@ public class GradleBuildInjectionExtension implements BeforeEachCallback { this.gradleBuild = new GradleBuild(); this.gradleBuild.gradleVersion(GradleVersions.minimumCompatible()); String bootVersion = System.getProperty("springBootVersion"); - Assert.notNull(bootVersion, "Property 'springBootVersion' must be set in build environment"); + Assert.state(bootVersion != null, "Property 'springBootVersion' must be set in build environment"); this.gradleBuild.bootVersion(bootVersion); }