Skip to content

Commit cf7e30f

Browse files
committed
Clarify when BootstrapContext get methods may return null
Closes gh-47896
1 parent 99f58de commit cf7e30f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BootstrapContext.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
* <p>
2828
* Provides lazy access to singletons that may be expensive to create, or need to be
2929
* shared before the {@link ApplicationContext} is available.
30+
* <p>
31+
* Instances are registered by type. The contact may return {@code null} values when a
32+
* type has been registered but no value is actually supplied.
3033
*
3134
* @author Phillip Webb
3235
* @since 2.4.0
36+
* @see BootstrapRegistry
3337
*/
3438
public interface BootstrapContext {
3539

@@ -38,7 +42,7 @@ public interface BootstrapContext {
3842
* will be created if it hasn't been accessed previously.
3943
* @param <T> the instance type
4044
* @param type the instance type
41-
* @return the instance managed by the context
45+
* @return the instance managed by the context, which may be {@code null}
4246
* @throws IllegalStateException if the type has not been registered
4347
*/
4448
<T> T get(Class<T> type) throws IllegalStateException;
@@ -49,7 +53,7 @@ public interface BootstrapContext {
4953
* @param <T> the instance type
5054
* @param type the instance type
5155
* @param other the instance to use if the type has not been registered
52-
* @return the instance
56+
* @return the instance, which may be {@code null}
5357
*/
5458
<T> T getOrElse(Class<T> type, T other);
5559

@@ -59,7 +63,7 @@ public interface BootstrapContext {
5963
* @param <T> the instance type
6064
* @param type the instance type
6165
* @param other a supplier for the instance to use if the type has not been registered
62-
* @return the instance
66+
* @return the instance, which may be {@code null}
6367
*/
6468
<T> T getOrElseSupply(Class<T> type, Supplier<T> other);
6569

@@ -70,7 +74,7 @@ public interface BootstrapContext {
7074
* @param <X> the exception to throw if the type is not registered
7175
* @param type the instance type
7276
* @param exceptionSupplier the supplier which will return the exception to be thrown
73-
* @return the instance managed by the context
77+
* @return the instance managed by the context, which may be {@code null}
7478
* @throws X if the type has not been registered
7579
* @throws IllegalStateException if the type has not been registered
7680
*/

0 commit comments

Comments
 (0)