Fixed possbile NullPointerException in parameterTypesString() (SWF-265).

This commit is contained in:
Erwin Vervaet
2007-03-21 21:24:47 +00:00
parent 49b2902493
commit 3f64765983
5 changed files with 23 additions and 12 deletions

View File

@@ -42,7 +42,9 @@ public class MethodKey implements Serializable {
private String methodName;
/**
* The method's actual parameter types.
* The method's actual parameter types. Could contain null values
* if the user did not specify a parameter type for the corresponding
* parameter
*/
private Class[] parameterTypes;
@@ -81,7 +83,8 @@ public class MethodKey implements Serializable {
}
/**
* Returns the method parameter types.
* Returns the method parameter types. Could contain null values
* if no type was specified for the corresponding parameter.
*/
public Class[] getParameterTypes() {
return parameterTypes;
@@ -104,7 +107,7 @@ public class MethodKey implements Serializable {
*/
protected Method resolveMethod() throws InvalidMethodKeyException {
try {
return declaredType.getMethod(methodName, getParameterTypes());
return declaredType.getMethod(methodName, parameterTypes);
}
catch (NoSuchMethodException e) {
Method method = findMethodConsiderAssignableParameterTypes();
@@ -126,7 +129,7 @@ public class MethodKey implements Serializable {
if (candidateMethods[i].getName().equals(methodName)) {
// Check if the method has the correct number of parameters.
Class[] candidateParameterTypes = candidateMethods[i].getParameterTypes();
if (candidateParameterTypes.length == getParameterTypes().length) {
if (candidateParameterTypes.length == parameterTypes.length) {
int numberOfCorrectArguments = 0;
for (int j = 0; j < candidateParameterTypes.length; j++) {
// Check if the candidate type is assignable to the sig
@@ -139,8 +142,7 @@ public class MethodKey implements Serializable {
}
}
else {
// just match on a null param type (effectively
// 'any')
// just match on a null param type (effectively 'any')
numberOfCorrectArguments++;
}
}
@@ -240,7 +242,12 @@ public class MethodKey implements Serializable {
private String parameterTypesString() {
StringBuffer parameterTypesString = new StringBuffer();
for (int i = 0; i < parameterTypes.length; i++) {
parameterTypesString.append(ClassUtils.getShortName(parameterTypes[i]));
if (parameterTypes[i] == null) {
parameterTypesString.append("<any>");
}
else {
parameterTypesString.append(ClassUtils.getShortName(parameterTypes[i]));
}
if (i < parameterTypes.length - 1) {
parameterTypesString.append(',');
}

View File

@@ -45,7 +45,7 @@ public class Parameter implements Serializable {
/**
* Create a new named parameter definition. Named parameters are capable of resolving
* parameter values (arguments) from argument sources.
* @param type the type the parameter type, may be null
* @param type the parameter type, may be null
* @param name the name the method argument expression (required)
*/
public Parameter(Class type, Expression name) {
@@ -55,7 +55,8 @@ public class Parameter implements Serializable {
}
/**
* Returns the parameter type.
* Returns the parameter type. Could be null if no parameter type
* was specified.
*/
public Class getType() {
return type;

View File

@@ -96,7 +96,9 @@ public class Parameters implements Serializable {
}
/**
* Get an array containing each parameter type.
* Get an array containing each parameter type. The resulting array
* could contain null values if the corresponding parameters did
* not specify a parameter type.
* @return the types
*/
public Class[] getTypesArray() {