Improve null-safety of core/spring-boot-testcontainers

See gh-46926
This commit is contained in:
Moritz Halbritter 2025-08-18 11:45:29 +02:00
parent 717ddac137
commit dc3fe1b17d
1 changed files with 4 additions and 3 deletions

View File

@ -193,12 +193,13 @@ public abstract class ContainerConnectionDetailsFactory<C extends Container<?>,
* @return the container instance * @return the container instance
*/ */
protected final C getContainer() { protected final C getContainer() {
Assert.state(this.container != null, C container = this.container;
Assert.state(container != null,
"Container cannot be obtained before the connection details bean has been initialized"); "Container cannot be obtained before the connection details bean has been initialized");
if (this.container instanceof Startable startable) { if (container instanceof Startable startable) {
TestcontainersStartup.start(startable); TestcontainersStartup.start(startable);
} }
return this.container; return container;
} }
/** /**