From e8452043657abf74a7e6aa2d0bee2875d0bd0ab4 Mon Sep 17 00:00:00 2001 From: Philipp Heuer Date: Thu, 6 Feb 2025 20:50:21 +0100 Subject: [PATCH 1/2] feat: use jspecify nullable annotations --- api/build.gradle.kts | 3 +- .../events4j/api/IEventManager.java | 18 ++++++++---- .../api/domain/DisposableWrapper.java | 3 +- .../api/domain/IEventSubscription.java | 5 ++++ .../events4j/api/service/IEventHandler.java | 5 ++-- .../api/service/IServiceMediator.java | 8 ++++-- core/build.gradle.kts | 5 +++- .../events4j/core/EventManager.java | 28 +++++++++++-------- .../events4j/core/domain/Event.java | 4 --- .../core/services/ServiceMediator.java | 10 +++---- handler-reactor/build.gradle.kts | 7 +++-- .../events4j/reactor/ReactorEventHandler.java | 8 ++++-- .../reactor/ReactorEventHandlerTest.java | 4 --- handler-simple/build.gradle.kts | 5 +++- .../events4j/simple/SimpleEventHandler.java | 8 ++++-- .../simple/domain/EventSubscriber.java | 4 --- handler-spring/build.gradle.kts | 7 +++-- .../events4j/spring/SpringEventHandler.java | 6 ++-- kotlin/build.gradle.kts | 4 +-- 19 files changed, 86 insertions(+), 56 deletions(-) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 1609b9e..673d832 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -9,5 +9,6 @@ projectConfiguration { } dependencies { - + // annotations + implementation("org.jspecify:jspecify:1.0.0") } diff --git a/api/src/main/java/com/github/philippheuer/events4j/api/IEventManager.java b/api/src/main/java/com/github/philippheuer/events4j/api/IEventManager.java index 30fdecc..febf460 100644 --- a/api/src/main/java/com/github/philippheuer/events4j/api/IEventManager.java +++ b/api/src/main/java/com/github/philippheuer/events4j/api/IEventManager.java @@ -4,6 +4,8 @@ import com.github.philippheuer.events4j.api.domain.IEventSubscription; import com.github.philippheuer.events4j.api.service.IEventHandler; import com.github.philippheuer.events4j.api.service.IServiceMediator; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import java.util.List; import java.util.function.Consumer; @@ -15,14 +17,14 @@ public interface IEventManager extends AutoCloseable { * * @param event Event */ - void publish(Object event); + void publish(@NonNull Object event); /** * Register EventHandler * * @param eventHandler IEventHandler */ - void registerEventHandler(IEventHandler eventHandler); + void registerEventHandler(@NonNull IEventHandler eventHandler); /** * Registers a new consumer based default event handler if supported @@ -32,13 +34,15 @@ public interface IEventManager extends AutoCloseable { * @param the event type * @return a new Disposable of the given eventType */ - IDisposable onEvent(Class eventClass, Consumer consumer); + @NonNull + IDisposable onEvent(@NonNull Class eventClass, @NonNull Consumer consumer); /** * Get the ServiceMediator * * @return ServiceMediator */ + @NonNull IServiceMediator getServiceMediator(); /** @@ -47,22 +51,25 @@ public interface IEventManager extends AutoCloseable { * @param eventHandlerClass the event handler class * @return boolean */ - boolean hasEventHandler(Class eventHandlerClass); + boolean hasEventHandler(@NonNull Class eventHandlerClass); /** * Retrieves a EventHandler of the provided type * * @param eventHandlerClass the event handler class * @param the eventHandler type + * @throws RuntimeException if no event handler of the provided type is registered * @return a reference to the requested event handler */ - E getEventHandler(Class eventHandlerClass); + @NonNull + E getEventHandler(@NonNull Class eventHandlerClass); /** * Gets all registered event handlers * * @return a list of all registered event handlers */ + @NonNull List getEventHandlers(); /** @@ -70,6 +77,7 @@ public interface IEventManager extends AutoCloseable { * * @return a list that holds IEventSubscription`s */ + @NonNull List getActiveSubscriptions(); } diff --git a/api/src/main/java/com/github/philippheuer/events4j/api/domain/DisposableWrapper.java b/api/src/main/java/com/github/philippheuer/events4j/api/domain/DisposableWrapper.java index 32adbe9..8eed379 100644 --- a/api/src/main/java/com/github/philippheuer/events4j/api/domain/DisposableWrapper.java +++ b/api/src/main/java/com/github/philippheuer/events4j/api/domain/DisposableWrapper.java @@ -2,6 +2,7 @@ import lombok.Getter; import lombok.ToString; +import org.jspecify.annotations.NonNull; import java.util.Map; import java.util.function.Consumer; @@ -24,7 +25,7 @@ public class DisposableWrapper implements IEventSubscription { private final Map activeSubscriptions; @SuppressWarnings("rawtypes") - public DisposableWrapper(IDisposable disposable, String id, Class eventType, Consumer consumer, Map activeSubscriptions) { + public DisposableWrapper(@NonNull IDisposable disposable, @NonNull String id, @NonNull Class eventType, @NonNull Consumer consumer, @NonNull Map activeSubscriptions) { this.disposable = disposable; this.id = id; this.eventType = eventType; diff --git a/api/src/main/java/com/github/philippheuer/events4j/api/domain/IEventSubscription.java b/api/src/main/java/com/github/philippheuer/events4j/api/domain/IEventSubscription.java index a3beb50..7966763 100644 --- a/api/src/main/java/com/github/philippheuer/events4j/api/domain/IEventSubscription.java +++ b/api/src/main/java/com/github/philippheuer/events4j/api/domain/IEventSubscription.java @@ -1,14 +1,19 @@ package com.github.philippheuer.events4j.api.domain; +import org.jspecify.annotations.NonNull; + import java.util.function.Consumer; public interface IEventSubscription extends IDisposable { + @NonNull String getId(); + @NonNull @SuppressWarnings("rawtypes") Class getEventType(); + @NonNull @SuppressWarnings("rawtypes") Consumer getConsumer(); diff --git a/api/src/main/java/com/github/philippheuer/events4j/api/service/IEventHandler.java b/api/src/main/java/com/github/philippheuer/events4j/api/service/IEventHandler.java index 07c50ea..8a62ba2 100644 --- a/api/src/main/java/com/github/philippheuer/events4j/api/service/IEventHandler.java +++ b/api/src/main/java/com/github/philippheuer/events4j/api/service/IEventHandler.java @@ -1,6 +1,7 @@ package com.github.philippheuer.events4j.api.service; import com.github.philippheuer.events4j.api.domain.IDisposable; +import lombok.NonNull; import java.util.function.Consumer; @@ -11,7 +12,7 @@ public interface IEventHandler extends AutoCloseable { * * @param event Event */ - void publish(Object event); + void publish(@NonNull Object event); /** * Registers a new consumer based default event handler if supported @@ -21,6 +22,6 @@ public interface IEventHandler extends AutoCloseable { * @param the event type * @return a new Disposable of the given eventType */ - IDisposable onEvent(Class eventClass, Consumer consumer); + IDisposable onEvent(@NonNull Class eventClass, @NonNull Consumer consumer); } diff --git a/api/src/main/java/com/github/philippheuer/events4j/api/service/IServiceMediator.java b/api/src/main/java/com/github/philippheuer/events4j/api/service/IServiceMediator.java index 2f17690..bc7131a 100644 --- a/api/src/main/java/com/github/philippheuer/events4j/api/service/IServiceMediator.java +++ b/api/src/main/java/com/github/philippheuer/events4j/api/service/IServiceMediator.java @@ -1,5 +1,7 @@ package com.github.philippheuer.events4j.api.service; +import org.jspecify.annotations.NonNull; + public interface IServiceMediator { /** @@ -8,7 +10,7 @@ public interface IServiceMediator { * @param serviceName The ServiceName * @param serviceInstance The ServiceInstance */ - void addService(String serviceName, Object serviceInstance); + void addService(@NonNull String serviceName, @NonNull Object serviceInstance); /** * Gets a service from the ServiceMediator @@ -16,8 +18,10 @@ public interface IServiceMediator { * @param serviceClass The ServiceClass you expect * @param serviceName The ServiceName * @param The type of the Service + * @throws RuntimeException if no service of the provided type and name is registered * @return The ServiceInstance */ - T getService(Class serviceClass, String serviceName); + @NonNull + T getService(@NonNull Class serviceClass, @NonNull String serviceName); } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d4b0fa4..3f12d21 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -9,8 +9,11 @@ projectConfiguration { } dependencies { - // Project + // project api(project(":api")) testImplementation(project(":handler-simple")) testImplementation(project(":handler-reactor")) + + // annotations + implementation("org.jspecify:jspecify:1.0.0") } diff --git a/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java b/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java index 173697a..d7c9958 100644 --- a/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java +++ b/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java @@ -10,6 +10,8 @@ import com.github.philippheuer.events4j.core.services.ServiceMediator; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -23,10 +25,6 @@ /** * The EventManager - * - * @author Philipp Heuer [https://github.com/PhilippHeuer] - * @version %I%, %G% - * @since 1.0 */ @Getter @Slf4j @@ -79,7 +77,7 @@ public EventManager() { * * @param eventHandler IEventHandler */ - public void registerEventHandler(IEventHandler eventHandler) { + public void registerEventHandler(@NonNull IEventHandler eventHandler) { if (!eventHandlers.contains(eventHandler)) { eventHandlers.add(eventHandler); eventHandlerCache.put(eventHandler.getClass().getCanonicalName(), eventHandler.getClass()); @@ -89,6 +87,7 @@ public void registerEventHandler(IEventHandler eventHandler) { /** * @return returns the list of all active subscriptions */ + @NonNull public List getActiveSubscriptions() { return Collections.unmodifiableList(new ArrayList<>(activeSubscriptions.values())); } @@ -126,7 +125,7 @@ public void autoDiscovery() { * * @param event A event of any kinds, should implement IEvent if possible */ - public void publish(Object event) { + public void publish(@NonNull Object event) { // check for stop if (isStopped) { log.warn("Tried to dispatch a event to a closed eventManager!"); @@ -163,7 +162,7 @@ public void publish(Object event) { * @param eventHandlerClass the event handler class * @return boolean */ - public boolean hasEventHandler(Class eventHandlerClass) { + public boolean hasEventHandler(@NonNull Class eventHandlerClass) { return getEventHandlers().stream().anyMatch(h -> h.getClass().getName().equalsIgnoreCase(eventHandlerClass.getName())); } @@ -174,7 +173,7 @@ public boolean hasEventHandler(Class eventHandlerClass) * @param the eventHandler type * @return a reference to the requested event handler */ - public E getEventHandler(Class eventHandlerClass) { + public E getEventHandler(@NonNull Class eventHandlerClass) { Optional eventHandler = getEventHandlers().stream().filter(h -> h.getClass().getName().equalsIgnoreCase(eventHandlerClass.getName())).map(h -> (E) h).findAny(); return eventHandler.orElseThrow(() -> new RuntimeException("No eventHandler of type " + eventHandlerClass.getName() + " is registered!")); } @@ -187,8 +186,14 @@ public E getEventHandler(Class eventHandlerClass) { * @param the event type * @return a new Disposable of the given eventType */ - public IEventSubscription onEvent(Class eventClass, Consumer consumer) { - return onEvent(consumer.getClass().getCanonicalName() + "/" + consumerSequence.getAndAdd(1), eventClass, consumer); + @NonNull + public IEventSubscription onEvent(@NonNull Class eventClass, @NonNull Consumer consumer) { + IEventSubscription sub; + do { + sub = onEvent(consumer.getClass().getCanonicalName() + "/" + consumerSequence.getAndAdd(1), eventClass, consumer); + } while (sub == null); + + return sub; } /** @@ -202,7 +207,8 @@ public IEventSubscription onEvent(Class eventClass, Consumer consumer) * @param the event type * @return a new Disposable of the given eventType */ - public synchronized IEventSubscription onEvent(String id, Class eventClass, Consumer consumer) { + @Nullable + public synchronized IEventSubscription onEvent(@NonNull String id, @NonNull Class eventClass, @NonNull Consumer consumer) { // return null if a disposable with the given id is already present when idUnique is set if (activeSubscriptions.containsKey(id)) { return null; diff --git a/core/src/main/java/com/github/philippheuer/events4j/core/domain/Event.java b/core/src/main/java/com/github/philippheuer/events4j/core/domain/Event.java index c524194..d62f084 100644 --- a/core/src/main/java/com/github/philippheuer/events4j/core/domain/Event.java +++ b/core/src/main/java/com/github/philippheuer/events4j/core/domain/Event.java @@ -13,10 +13,6 @@ /** * Used to represent an event. - * - * @author Philipp Heuer [https://github.com/PhilippHeuer] - * @version %I%, %G% - * @since 1.0 */ @Data public abstract class Event implements IEvent { diff --git a/core/src/main/java/com/github/philippheuer/events4j/core/services/ServiceMediator.java b/core/src/main/java/com/github/philippheuer/events4j/core/services/ServiceMediator.java index 970abdc..7362c1f 100644 --- a/core/src/main/java/com/github/philippheuer/events4j/core/services/ServiceMediator.java +++ b/core/src/main/java/com/github/philippheuer/events4j/core/services/ServiceMediator.java @@ -3,6 +3,7 @@ import com.github.philippheuer.events4j.api.IEventManager; import com.github.philippheuer.events4j.api.service.IServiceMediator; import lombok.Getter; +import org.jspecify.annotations.NonNull; import java.util.HashMap; import java.util.Map; @@ -11,10 +12,6 @@ * The ServiceMediator *

* The ServiceMediator provides access to 3rd party services for your custom events - * - * @author Philipp Heuer [https://github.com/PhilippHeuer] - * @version %I%, %G% - * @since 1.0 */ public final class ServiceMediator implements IServiceMediator { @@ -44,7 +41,7 @@ public ServiceMediator(final IEventManager eventManager) { * @param serviceName The ServiceName * @param serviceInstance The ServiceInstance */ - public void addService(String serviceName, Object serviceInstance) { + public void addService(@NonNull String serviceName, @NonNull Object serviceInstance) { serviceReferences.put(serviceName, serviceInstance); } @@ -56,7 +53,8 @@ public void addService(String serviceName, Object serviceInstance) { * @param The type of the Service * @return The ServiceInstance */ - public T getService(Class serviceClass, String serviceName) { + @NonNull + public T getService(@NonNull Class serviceClass, @NonNull String serviceName) { Object serviceInstance = serviceReferences.get(serviceName); if (serviceClass.isInstance(serviceInstance)) { diff --git a/handler-reactor/build.gradle.kts b/handler-reactor/build.gradle.kts index 675aa0a..16abb03 100644 --- a/handler-reactor/build.gradle.kts +++ b/handler-reactor/build.gradle.kts @@ -9,12 +9,15 @@ projectConfiguration { } dependencies { - // Project + // project api(project(":api")) testImplementation(project(":core")) - // Reactor - see https://repo1.maven.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR12/reactor-bom-Dysprosium-SR12.pom + // reactor - see https://repo1.maven.org/maven2/io/projectreactor/reactor-bom/Dysprosium-SR12/reactor-bom-Dysprosium-SR12.pom api("io.projectreactor:reactor-core:3.7.2") api("io.projectreactor.addons:reactor-extra:3.5.2") testImplementation("io.projectreactor:reactor-test:3.7.2") + + // annotations + implementation("org.jspecify:jspecify:1.0.0") } diff --git a/handler-reactor/src/main/java/com/github/philippheuer/events4j/reactor/ReactorEventHandler.java b/handler-reactor/src/main/java/com/github/philippheuer/events4j/reactor/ReactorEventHandler.java index 0ecdf64..ef41e55 100644 --- a/handler-reactor/src/main/java/com/github/philippheuer/events4j/reactor/ReactorEventHandler.java +++ b/handler-reactor/src/main/java/com/github/philippheuer/events4j/reactor/ReactorEventHandler.java @@ -5,6 +5,7 @@ import com.github.philippheuer.events4j.reactor.util.Events4JSubscriber; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.jspecify.annotations.NonNull; import org.reactivestreams.Subscriber; import reactor.core.publisher.EmitterProcessor; import reactor.core.publisher.Flux; @@ -53,7 +54,7 @@ public ReactorEventHandler() { * * @param scheduler The scheduler provides some guarantees required by Reactive Streams flows like FIFO execution * @param processor Used to bridge gateway events to the subscribers - * @param overflowStrategy Safely gates a multi-threaded producer. + * @param overflowStrategy Safely gates a multithreaded producer. * @deprecated {@link FluxProcessor} is deprecated. */ @Deprecated @@ -64,7 +65,7 @@ public ReactorEventHandler(Scheduler scheduler, FluxProcessor pr } @Override - public void publish(Object event) { + public void publish(@NonNull Object event) { // publish event eventSink.next(event); } @@ -77,8 +78,9 @@ public void publish(Object event) { * @param the event type * @return a new {@link reactor.core.publisher.Flux} of the given eventType */ + @NonNull @Override - public IDisposable onEvent(Class eventClass, Consumer consumer) { + public IDisposable onEvent(@NonNull Class eventClass, @NonNull Consumer consumer) { Flux flux = processor .publishOn(this.scheduler) .ofType(eventClass); diff --git a/handler-reactor/src/test/java/com/github/philippheuer/events4j/reactor/ReactorEventHandlerTest.java b/handler-reactor/src/test/java/com/github/philippheuer/events4j/reactor/ReactorEventHandlerTest.java index efb79a3..ef246fb 100644 --- a/handler-reactor/src/test/java/com/github/philippheuer/events4j/reactor/ReactorEventHandlerTest.java +++ b/handler-reactor/src/test/java/com/github/philippheuer/events4j/reactor/ReactorEventHandlerTest.java @@ -16,10 +16,6 @@ /** * Reactor EventHandler Test - * - * @author Philipp Heuer [https://github.com/PhilippHeuer] - * @version %I%, %G% - * @since 1.0 */ class ReactorEventHandlerTest { diff --git a/handler-simple/build.gradle.kts b/handler-simple/build.gradle.kts index ef63762..001313e 100644 --- a/handler-simple/build.gradle.kts +++ b/handler-simple/build.gradle.kts @@ -9,7 +9,10 @@ projectConfiguration { } dependencies { - // Project + // project api(project(":api")) testImplementation(project(":core")) + + // annotations + implementation("org.jspecify:jspecify:1.0.0") } diff --git a/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/SimpleEventHandler.java b/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/SimpleEventHandler.java index 7e263a0..e9cae7a 100644 --- a/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/SimpleEventHandler.java +++ b/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/SimpleEventHandler.java @@ -7,6 +7,7 @@ import com.github.philippheuer.events4j.simple.util.ClassUtil; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.jspecify.annotations.NonNull; import java.lang.reflect.Method; import java.util.List; @@ -47,7 +48,8 @@ public void registerListener(Object eventListener) { * @param the event type * @return a new Disposable of the given eventType */ - public IDisposable onEvent(Class eventClass, Consumer consumer) { + @NonNull + public IDisposable onEvent(@NonNull Class eventClass, @NonNull Consumer consumer) { // register final List> eventHandlers = consumerBasedHandlers.computeIfAbsent(eventClass, s -> new CopyOnWriteArrayList<>()); //noinspection unchecked @@ -96,7 +98,7 @@ private void registerListener(Class eventListenerClass, Object eventListener) * * @param event The event that will be dispatched to the simple based method listeners. */ - public void publish(Object event) { + public void publish(@NonNull Object event) { handleConsumerHandlers(event); handleAnnotationHandlers(event); } @@ -120,7 +122,7 @@ private void handleConsumerHandlers(Object event) { * @param event The event that will be dispatched to the simple based method listeners. */ private void handleAnnotationHandlers(Object event) { - if (methodListeners.size() > 0) { + if (!methodListeners.isEmpty()) { for (Map.Entry, ConcurrentMap>> e : methodListeners.entrySet()) { if (e.getKey().isAssignableFrom(event.getClass())) { ConcurrentMap> eventClass = e.getValue(); diff --git a/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/domain/EventSubscriber.java b/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/domain/EventSubscriber.java index 272f3d3..648c29f 100644 --- a/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/domain/EventSubscriber.java +++ b/handler-simple/src/main/java/com/github/philippheuer/events4j/simple/domain/EventSubscriber.java @@ -7,10 +7,6 @@ /** * Marks method that only have a event as parameter and should handle said event - * - * @author Philipp Heuer [https://github.com/PhilippHeuer] - * @version %I%, %G% - * @since 1.0 */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) diff --git a/handler-spring/build.gradle.kts b/handler-spring/build.gradle.kts index db26237..e5bf5b3 100644 --- a/handler-spring/build.gradle.kts +++ b/handler-spring/build.gradle.kts @@ -9,11 +9,14 @@ projectConfiguration { } dependencies { - // Project + // project api(project(":api")) testImplementation(project(":core")) - // Spring + // spring api("org.springframework.boot:spring-boot-starter:2.7.18") testImplementation("org.springframework.boot:spring-boot-starter-test:2.7.18") + + // annotations + implementation("org.jspecify:jspecify:1.0.0") } diff --git a/handler-spring/src/main/java/com/github/philippheuer/events4j/spring/SpringEventHandler.java b/handler-spring/src/main/java/com/github/philippheuer/events4j/spring/SpringEventHandler.java index 269a89a..3392e8a 100644 --- a/handler-spring/src/main/java/com/github/philippheuer/events4j/spring/SpringEventHandler.java +++ b/handler-spring/src/main/java/com/github/philippheuer/events4j/spring/SpringEventHandler.java @@ -4,6 +4,7 @@ import com.github.philippheuer.events4j.api.service.IEventHandler; import com.github.philippheuer.events4j.spring.domain.SpringListenerSubscription; import lombok.extern.slf4j.Slf4j; +import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; @@ -30,12 +31,13 @@ public SpringEventHandler(ApplicationEventMulticaster applicationEventMulticaste this.applicationEventPublisher = applicationEventPublisher; } - public void publish(Object event) { + public void publish(@NonNull Object event) { applicationEventPublisher.publishEvent(event); } + @NonNull @Override - public IDisposable onEvent(Class eventClass, Consumer consumer) { + public IDisposable onEvent(@NonNull Class eventClass, @NonNull Consumer consumer) { ApplicationListener listener = event -> { if (event instanceof PayloadApplicationEvent) { PayloadApplicationEvent pae = (PayloadApplicationEvent) event; diff --git a/kotlin/build.gradle.kts b/kotlin/build.gradle.kts index 6844a46..e0f6dc0 100644 --- a/kotlin/build.gradle.kts +++ b/kotlin/build.gradle.kts @@ -11,11 +11,11 @@ projectConfiguration { } dependencies { - // Project + // project api(project(":api")) api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1") - // Testing + // testing testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.1") testImplementation(project(":core")) testImplementation(project(":handler-simple")) From fa8b3fec332c0a32e69139f6e12424f6a40bd019 Mon Sep 17 00:00:00 2001 From: Philipp Heuer <10275049+PhilippHeuer@users.noreply.github.com> Date: Fri, 7 Feb 2025 01:09:11 +0100 Subject: [PATCH 2/2] Update core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java Co-authored-by: iProdigy <8106344+iProdigy@users.noreply.github.com> --- .../java/com/github/philippheuer/events4j/core/EventManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java b/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java index d7c9958..36ed509 100644 --- a/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java +++ b/core/src/main/java/com/github/philippheuer/events4j/core/EventManager.java @@ -173,6 +173,7 @@ public boolean hasEventHandler(@NonNull Class eventHand * @param the eventHandler type * @return a reference to the requested event handler */ + @NonNull public E getEventHandler(@NonNull Class eventHandlerClass) { Optional eventHandler = getEventHandlers().stream().filter(h -> h.getClass().getName().equalsIgnoreCase(eventHandlerClass.getName())).map(h -> (E) h).findAny(); return eventHandler.orElseThrow(() -> new RuntimeException("No eventHandler of type " + eventHandlerClass.getName() + " is registered!"));