Permalink
Browse files

Throw IllegalArgumentException if parameters do not match

  • Loading branch information...
1 parent e58a63a commit 9c492a730f829f8005b028e9d86909997b4ac922 @stuartwdouglas stuartwdouglas committed May 20, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/main/java/org/jboss/invocation/InterceptorContext.java
View
12 src/main/java/org/jboss/invocation/InterceptorContext.java
@@ -316,6 +316,18 @@ public Method getMethod() {
}
public void setParameters(final Object[] params) {
+ if (method != null) {
+ final Class<?>[] parameterTypes = method.getParameterTypes();
+ if (params.length != parameterTypes.length) {
+ throw new IllegalArgumentException("Number of parameters must match number of method arguments");
+ }
+ for (int i = 0; i < params.length; ++i) {
+ final Class<?> type = parameterTypes[i];
+ if (!type.isAssignableFrom(params[i].getClass())) {
+ throw new IllegalArgumentException("Parameter " + i + " (" + params[i] + ") is not assignable to method parameter type " + parameterTypes[i]);
+ }
+ }
+ }
parameters = params;
}

0 comments on commit 9c492a7

Please sign in to comment.