From 78ce2d79f2b1341bfc366b1fde487d960493a08a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Fri, 15 Jul 2022 09:19:10 -0400 Subject: More precise exceptions --- .../commons/lang3/event/EventListenerSupport.java | 17 +++++++++-------- .../commons/lang3/event/EventListenerSupportTest.java | 12 ++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/event/EventListenerSupport.java b/src/main/java/org/apache/commons/lang3/event/EventListenerSupport.java index db2ac8fdb..92c371591 100644 --- a/src/main/java/org/apache/commons/lang3/event/EventListenerSupport.java +++ b/src/main/java/org/apache/commons/lang3/event/EventListenerSupport.java @@ -23,6 +23,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; @@ -311,19 +312,19 @@ public class EventListenerSupport implements Serializable { protected class ProxyInvocationHandler implements InvocationHandler { /** - * Propagates the method call to all registered listeners in place of - * the proxy listener object. + * Propagates the method call to all registered listeners in place of the proxy listener object. * - * @param unusedProxy the proxy object representing a listener on which the - * invocation was called; not used - * @param method the listener method that will be called on all of the - * listeners. + * @param unusedProxy the proxy object representing a listener on which the invocation was called; not used + * @param method the listener method that will be called on all of the listeners. * @param args event arguments to propagate to the listeners. * @return the result of the method call - * @throws Throwable if an error occurs + * @throws InvocationTargetException if an error occurs + * @throws IllegalArgumentException if an error occurs + * @throws IllegalAccessException if an error occurs */ @Override - public Object invoke(final Object unusedProxy, final Method method, final Object[] args) throws Throwable { + public Object invoke(final Object unusedProxy, final Method method, final Object[] args) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { for (final L listener : listeners) { method.invoke(listener, args); } diff --git a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java index 70658a746..1b730dc1e 100644 --- a/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java +++ b/src/test/java/org/apache/commons/lang3/event/EventListenerSupportTest.java @@ -29,6 +29,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Date; @@ -174,22 +175,17 @@ public class EventListenerSupportTest extends AbstractLangTest { @Test public void testSubclassInvocationHandling() throws PropertyVetoException { - final - EventListenerSupport eventListenerSupport = new EventListenerSupport( + final EventListenerSupport eventListenerSupport = new EventListenerSupport( VetoableChangeListener.class) { private static final long serialVersionUID = 1L; @Override protected java.lang.reflect.InvocationHandler createInvocationHandler() { return new ProxyInvocationHandler() { - /** - * {@inheritDoc} - */ @Override public Object invoke(final Object proxy, final Method method, final Object[] args) - throws Throwable { - return "vetoableChange".equals(method.getName()) - && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + return "vetoableChange".equals(method.getName()) && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null : super.invoke(proxy, method, args); } }; -- cgit v1.2.3