Index: main/java/java/beans/EventHandler.java =================================================================== --- main/java/java/beans/EventHandler.java (revision 469500) +++ main/java/java/beans/EventHandler.java (working copy) @@ -85,10 +85,18 @@ // we have a valid listener method at this point result = m.invoke(target, args); + } catch (RuntimeException e) { + throw e; } catch (Throwable t) { System.out .println(t.getClass() + ": " + t.getMessage()); //$NON-NLS-1$ } + } else { + // in order to be compatible with RI + if (listenerMethodName.equals(method.getName())) { + throw new IllegalArgumentException(Messages.getString( + "beans.4D")); + } } } } @@ -112,28 +120,28 @@ return target; } - public static T create(Class listenerInterface, Object target, String action, - String eventPropertyName, String listenerMethodName) { - Object proxy = Proxy.newProxyInstance(target.getClass().getClassLoader(), - new Class[] { listenerInterface }, new EventHandler(target, action, - eventPropertyName, listenerMethodName)); - return listenerInterface.cast(proxy); + @SuppressWarnings("unchecked") + public static T create(Class listenerInterface, Object target, + String action, String eventPropertyName, String listenerMethodName) { + return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), + new Class[] { listenerInterface }, new EventHandler(target, + action, eventPropertyName, listenerMethodName)); } - public static T create(Class listenerInterface, Object target, String action, - String eventPropertyName) { - Object proxy = Proxy.newProxyInstance(target.getClass().getClassLoader(), - new Class[] { listenerInterface }, new EventHandler(target, action, - eventPropertyName, null)); - return listenerInterface.cast(proxy); + @SuppressWarnings("unchecked") + public static T create(Class listenerInterface, Object target, + String action, String eventPropertyName) { + return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), + new Class[] { listenerInterface }, new EventHandler(target, + action, eventPropertyName, null)); } - public static T create(Class listenerInterface, Object target, String action) { - Object proxy = Proxy - .newProxyInstance(target.getClass().getClassLoader(), - new Class[] { listenerInterface }, new EventHandler(target, action, - null, null)); - return listenerInterface.cast(proxy); + @SuppressWarnings("unchecked") + public static T create(Class listenerInterface, Object target, + String action) { + return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), + new Class[] { listenerInterface }, new EventHandler(target, + action, null, null)); } private boolean isValidInvocation(Method method, Object[] arguments) { @@ -164,8 +172,8 @@ private Object[] getArgs(Object[] arguments) throws Exception { if (eventPropertyName == null) { return new Object[] {}; - } else if ((arguments == null) || (arguments.length == 0) - || (arguments[0] == null)) { + } else if ((arguments == null) || (arguments.length == 0)) { +// || (arguments[0] == null)) { return arguments; } else { Object arg = arguments[0]; @@ -174,7 +182,7 @@ while (st.hasMoreTokens()) { String propertyName = st.nextToken(); PropertyDescriptor pd = findPropertyDescriptor(arg.getClass(), - propertyName); + propertyName);; if (pd != null) { Method getter = pd.getReadMethod(); @@ -192,7 +200,9 @@ if (method != null) { arg = method.invoke(null, new Object[] {}); } else { - throw new IntrospectionException(Messages.getString( + // cannot access property getter + // RI thorws NPE here so we should do the same + throw new NullPointerException(Messages.getString( "beans.12", propertyName)); //$NON-NLS-1$ } } @@ -253,13 +263,15 @@ "beans.13", action)); //$NON-NLS-1$ } } else { - throw new Exception(Messages.getString("beans.14")); //$NON-NLS-1$ + throw new IndexOutOfBoundsException( + Messages.getString("beans.14")); //$NON-NLS-1$ } } else { return result; } } catch (IntrospectionException ie) { - throw new Exception(Messages.getString("beans.14")); //$NON-NLS-1$ + throw new IndexOutOfBoundsException( + Messages.getString("beans.14")); //$NON-NLS-1$ } return result; Index: main/java/org/apache/harmony/beans/internal/nls/messages.properties =================================================================== --- main/java/org/apache/harmony/beans/internal/nls/messages.properties (revision 469533) +++ main/java/org/apache/harmony/beans/internal/nls/messages.properties (working copy) @@ -92,4 +92,4 @@ beans.4A=newInstance is null beans.4B=type is null beans.4C=encoder is null - +beans.4D=Invalid method call