-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed as not planned
Closed as not planned
Copy link
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: bugA general bugA general bug
Description
When null is returned from the supplier passed to SingletonSupplier and some non-null value on subsequent calls, it breaks the singleton nature.
It returns on first call of singletonSupplier.get() null and then afterwards Hello.
private static int call = 0;
public static void main(String[] args) {
SingletonSupplier<String> singletonSupplier = SingletonSupplier.ofNullable(() -> supply());
System.out.println(singletonSupplier.get());
System.out.println(singletonSupplier.get());
System.out.println(singletonSupplier.get());
System.out.println(singletonSupplier.get());
}
private static String supply() {
call++;
if (call % 2 == 1) {
return null;
}
return "Hello";
}prints
null
Hello
Hello
Hello
In Framework 7 it has this signature:
public static <T> @Nullable SingletonSupplier<T> ofNullable(@Nullable Supplier<@Nullable T> supplier) {suggesting that using a Supplier<@Nullable String> is fine.
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: bugA general bugA general bug