From 8a30493c52cee87cf7e3f0f12c9ddbd2bfafced3 Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 19 Feb 2021 11:34:58 +0100 Subject: [PATCH] Warn about unused event handler return values If an event handler has a non-void return type, a warning is issued as the event bus cannot use the returned value. In rare cases this might be justified as the event handler could be invoked directly. --- .../src/main/java/dev/kske/eventbus/proc/EventProcessor.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/event-bus-proc/src/main/java/dev/kske/eventbus/proc/EventProcessor.java b/event-bus-proc/src/main/java/dev/kske/eventbus/proc/EventProcessor.java index 9d9122c..fed6f1c 100644 --- a/event-bus-proc/src/main/java/dev/kske/eventbus/proc/EventProcessor.java +++ b/event-bus-proc/src/main/java/dev/kske/eventbus/proc/EventProcessor.java @@ -63,6 +63,10 @@ public class EventProcessor extends AbstractProcessor { else pass = true; + // Warn the user about unused return values + if (useParameter && eventHandler.getReturnType().getKind() != TypeKind.VOID) + warning(eventHandler, "Unused return value"); + // Abort checking if the handler signature is incorrect if (!pass) continue;