diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java index 99b6e16eae..a959f5e2ad 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -86,7 +86,6 @@ public class ReactiveAdapterRegistry { * Create a registry and auto-register default adapters. * @see #getSharedInstance() */ - @SuppressWarnings("unchecked") public ReactiveAdapterRegistry() { // Defensive guard for the Reactive Streams API itself if (!reactiveStreamsPresent) { @@ -115,10 +114,7 @@ public class ReactiveAdapterRegistry { // Simple Flow.Publisher bridge if Reactor is not present if (!reactorPresent) { - this.adapters.add(new ReactiveAdapter( - ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> PublisherToRS.EMPTY_FLOW), - source -> new PublisherToRS<>((Flow.Publisher) source), - source -> new PublisherToFlow<>((Publisher) source))); + new FlowBridgeRegistrar().registerAdapter(this); } } @@ -375,6 +371,18 @@ public class ReactiveAdapterRegistry { } + private static class FlowBridgeRegistrar { + + @SuppressWarnings("unchecked") + void registerAdapter(ReactiveAdapterRegistry registry) { + registry.registerReactiveType( + ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> PublisherToRS.EMPTY_FLOW), + source -> new PublisherToRS<>((Flow.Publisher) source), + source -> new PublisherToFlow<>((Publisher) source)); + } + } + + private static class PublisherToFlow implements Flow.Publisher { private static final Flow.Subscription EMPTY_SUBSCRIPTION = new Flow.Subscription() {