Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Version 2
-
None
-
None
-
Doesn't relate to platform.
Description
Wrong implementation of getMethod() in InterfaceExtensionImpl class could lead to ArrayIndexOutOfBoundsException.
Old implementation :
static JMethod getMethod(JClass cls, String name, JClass[] paramTypes)
{
JMethod[] methods = cls.getMethods();
for (int i = 0; i < methods.length; i++)
{
JMethod method = methods[i];
if (!name.equals(method.getSimpleName()))
continue;
JParameter[] mParams = method.getParameters();
for (int j = 0; j < mParams.length; j++)
return method;
}
return null;
}
Correct impl-tion :
static JMethod getMethod(JClass cls, String name, JClass[] paramTypes)
{
JMethod[] methods = cls.getMethods();
for (int i = 0; i < methods.length; i++)
{
JMethod method = methods[i];
if (!name.equals(method.getSimpleName()))
continue;
JParameter[] mParams = method.getParameters();
// here was bug in possibe ArrayIndexOutOfBoundsException.
// because methods could have same names but different
// number of parameters
if ( mParams.length != paramTypes.length ){ continue; }
for (int j = 0; j < mParams.length; j++)
{ JParameter mParam = mParams[j]; if (!mParam.getType().equals(paramTypes[j])) continue; }
return method;
}
return null;
}