Skip to content

Commit 0078f46

Browse files
committed
Use reflection for JdkFlowAdapter
To avoid compiler issues on Eclipse.
1 parent 928b780 commit 0078f46

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,25 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
280280
private static class ReactorJdkFlowAdapterRegistrar {
281281

282282
void registerAdapter(ReactiveAdapterRegistry registry) throws Exception {
283+
283284
// TODO: remove reflection when build requires JDK 9+
284-
Class<?> type = ClassUtils.forName("java.util.concurrent.Flow.Publisher", getClass().getClassLoader());
285-
Method toFluxMethod = getMethod("flowPublisherToFlux", type);
286-
Method toFlowMethod = getMethod("publisherToFlowPublisher", Publisher.class);
285+
286+
String publisherName = "java.util.concurrent.Flow.Publisher";
287+
Class<?> publisherClass = ClassUtils.forName(publisherName, getClass().getClassLoader());
288+
289+
String adapterName = "reactor.adapter.JdkFlowAdapter";
290+
Class<?> flowAdapterClass = ClassUtils.forName(adapterName, getClass().getClassLoader());
291+
292+
Method toFluxMethod = flowAdapterClass.getMethod("flowPublisherToFlux", publisherClass);
293+
Method toFlowMethod = flowAdapterClass.getMethod("publisherToFlowPublisher", Publisher.class);
287294
Object emptyFlow = ReflectionUtils.invokeMethod(toFlowMethod, null, Flux.empty());
288295

289296
registry.registerReactiveType(
290-
ReactiveTypeDescriptor.multiValue(type, () -> emptyFlow),
297+
ReactiveTypeDescriptor.multiValue(publisherClass, () -> emptyFlow),
291298
source -> (Publisher<?>) ReflectionUtils.invokeMethod(toFluxMethod, null, source),
292299
publisher -> ReflectionUtils.invokeMethod(toFlowMethod, null, publisher)
293300
);
294301
}
295-
296-
private static Method getMethod(String name, Class<?> argumentType) throws NoSuchMethodException {
297-
return reactor.adapter.JdkFlowAdapter.class.getMethod(name, argumentType);
298-
}
299302
}
300303

301304

0 commit comments

Comments
 (0)