#344 ArrayIndexOutOfBounds with polymorphic Java methods

v8.4
closed
Michael Kay
5
2015-02-14
2005-04-11
Michael Kay
No

An ArrayIndexOutOfBounds exception may occur if a
stylesheet or query contains a call on a Java extension
function. The failure occurs if the function call has N
arguments, and the relevant Java class contains both a
static method with N arguments and a non-static method
with N-1 arguments, both of which match the name of the
function.

Source fix:

In the two calls on getBestFit() on lines 449 and 912,
add a third argument theClass, so the calls become

449:
AccessibleObject method =
getBestFit(candidateMethods, staticArgs, theClass);

912:
AccessibleObject method =
getBestFit(candidateMethods, argument, theClass);

Add the parameter to the method declaration on line
476, so that it becomes:

476:
private AccessibleObject getBestFit(List
candidateMethods, Expression[] args, Class theClass) {

Add the argument theClass to the three calls on
getConversionPreferences() on lines 503, 522, and 532,
so the calls become:

503:
int[] pref_i =
getConversionPreferences(
args,
(AccessibleObject)
candidateMethods.get(i), theClass);

522:
int[] pref_i = getConversionPreferences(
args,
(AccessibleObject)
candidateMethods.get(i), theClass);

532:
int[] pref_j =
getConversionPreferences(
args,
(AccessibleObject)
candidateMethods.get(j), theClass);

Add the parameter to the method declaration on line
633, so that it becomes:

633:

private int[] getConversionPreferences(Expression[]

args, AccessibleObject method, Class theClass) {

Change line 653 from

    int noOfArgs = args.length - firstArg;

to:

    int noOfArgs = args.length;

Change line 660 from

    for (int i = 0; i < noOfArgs; i++) {
        preferences[i] =

getConversionPreference(args[i + firstArg], params[i +
firstParam]
);

to

    for (int i = firstArg; i < noOfArgs; i++) {

        preferences[i] =

getConversionPreference(args[i], params[i + firstParam
- firstArg]
);

At line 667 add:

    if (firstArg == 1) {
        preferences[0] =

getConversionPreference(args[0], theClass);
if (preferences[0] == -1) {
return null;
}
}

Michael Kay

Discussion