You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/07/15 14:31:24 UTC
[commons-lang] 01/04: More precise exceptions
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 78ce2d79f2b1341bfc366b1fde487d960493a08a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 15 09:19:10 2022 -0400
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<L> 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<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
+ final EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
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);
}
};