Skip to content

Commit c4896ac

Browse files
committed
Defensively register Flow bridge in delegate class
See gh-31000
1 parent 3b09375 commit c4896ac

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public class ReactiveAdapterRegistry {
8686
* Create a registry and auto-register default adapters.
8787
* @see #getSharedInstance()
8888
*/
89-
@SuppressWarnings("unchecked")
9089
public ReactiveAdapterRegistry() {
9190
// Defensive guard for the Reactive Streams API itself
9291
if (!reactiveStreamsPresent) {
@@ -115,10 +114,7 @@ public ReactiveAdapterRegistry() {
115114

116115
// Simple Flow.Publisher bridge if Reactor is not present
117116
if (!reactorPresent) {
118-
this.adapters.add(new ReactiveAdapter(
119-
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> PublisherToRS.EMPTY_FLOW),
120-
source -> new PublisherToRS<>((Flow.Publisher<Object>) source),
121-
source -> new PublisherToFlow<>((Publisher<Object>) source)));
117+
new FlowBridgeRegistrar().registerAdapter(this);
122118
}
123119
}
124120

@@ -375,6 +371,18 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
375371
}
376372

377373

374+
private static class FlowBridgeRegistrar {
375+
376+
@SuppressWarnings("unchecked")
377+
void registerAdapter(ReactiveAdapterRegistry registry) {
378+
registry.registerReactiveType(
379+
ReactiveTypeDescriptor.multiValue(Flow.Publisher.class, () -> PublisherToRS.EMPTY_FLOW),
380+
source -> new PublisherToRS<>((Flow.Publisher<Object>) source),
381+
source -> new PublisherToFlow<>((Publisher<Object>) source));
382+
}
383+
}
384+
385+
378386
private static class PublisherToFlow<T> implements Flow.Publisher<T> {
379387

380388
private static final Flow.Subscription EMPTY_SUBSCRIPTION = new Flow.Subscription() {

0 commit comments

Comments
 (0)