From 0078f4677957a3d0c582cf19a145a390cd33ea9a Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 13 Jun 2018 09:38:54 -0400 Subject: [PATCH] Use reflection for JdkFlowAdapter To avoid compiler issues on Eclipse. --- .../core/ReactiveAdapterRegistry.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 0a6e253d94..374b339c1e 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -280,22 +280,25 @@ public class ReactiveAdapterRegistry { private static class ReactorJdkFlowAdapterRegistrar { void registerAdapter(ReactiveAdapterRegistry registry) throws Exception { + // TODO: remove reflection when build requires JDK 9+ - Class type = ClassUtils.forName("java.util.concurrent.Flow.Publisher", getClass().getClassLoader()); - Method toFluxMethod = getMethod("flowPublisherToFlux", type); - Method toFlowMethod = getMethod("publisherToFlowPublisher", Publisher.class); + + String publisherName = "java.util.concurrent.Flow.Publisher"; + Class publisherClass = ClassUtils.forName(publisherName, getClass().getClassLoader()); + + String adapterName = "reactor.adapter.JdkFlowAdapter"; + Class flowAdapterClass = ClassUtils.forName(adapterName, getClass().getClassLoader()); + + Method toFluxMethod = flowAdapterClass.getMethod("flowPublisherToFlux", publisherClass); + Method toFlowMethod = flowAdapterClass.getMethod("publisherToFlowPublisher", Publisher.class); Object emptyFlow = ReflectionUtils.invokeMethod(toFlowMethod, null, Flux.empty()); registry.registerReactiveType( - ReactiveTypeDescriptor.multiValue(type, () -> emptyFlow), + ReactiveTypeDescriptor.multiValue(publisherClass, () -> emptyFlow), source -> (Publisher) ReflectionUtils.invokeMethod(toFluxMethod, null, source), publisher -> ReflectionUtils.invokeMethod(toFlowMethod, null, publisher) ); } - - private static Method getMethod(String name, Class argumentType) throws NoSuchMethodException { - return reactor.adapter.JdkFlowAdapter.class.getMethod(name, argumentType); - } }