From cf7e30f2252affcb2c5dabc3367597cd6f8b17e9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 31 Oct 2025 09:24:29 -0700 Subject: [PATCH] Clarify when BootstrapContext get methods may return null Closes gh-47896 --- .../org/springframework/boot/BootstrapContext.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapContext.java index 3abc682e543..5f283ebde92 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapContext.java @@ -27,9 +27,13 @@ import org.springframework.core.env.Environment; *

* Provides lazy access to singletons that may be expensive to create, or need to be * shared before the {@link ApplicationContext} is available. + *

+ * Instances are registered by type. The contact may return {@code null} values when a + * type has been registered but no value is actually supplied. * * @author Phillip Webb * @since 2.4.0 + * @see BootstrapRegistry */ public interface BootstrapContext { @@ -38,7 +42,7 @@ public interface BootstrapContext { * will be created if it hasn't been accessed previously. * @param the instance type * @param type the instance type - * @return the instance managed by the context + * @return the instance managed by the context, which may be {@code null} * @throws IllegalStateException if the type has not been registered */ T get(Class type) throws IllegalStateException; @@ -49,7 +53,7 @@ public interface BootstrapContext { * @param the instance type * @param type the instance type * @param other the instance to use if the type has not been registered - * @return the instance + * @return the instance, which may be {@code null} */ T getOrElse(Class type, T other); @@ -59,7 +63,7 @@ public interface BootstrapContext { * @param the instance type * @param type the instance type * @param other a supplier for the instance to use if the type has not been registered - * @return the instance + * @return the instance, which may be {@code null} */ T getOrElseSupply(Class type, Supplier other); @@ -70,7 +74,7 @@ public interface BootstrapContext { * @param the exception to throw if the type is not registered * @param type the instance type * @param exceptionSupplier the supplier which will return the exception to be thrown - * @return the instance managed by the context + * @return the instance managed by the context, which may be {@code null} * @throws X if the type has not been registered * @throws IllegalStateException if the type has not been registered */