Bug 56636

Summary: EL defineFunction method signature parser fails to correctly match signatures to methods
Product: Tomcat 8 Reporter: Arthur Fiedler <artfiedler>
Component: ELAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.0.x-trunk   
Target Milestone: ----   
Hardware: PC   
OS: All   

Description Arthur Fiedler 2014-06-17 19:25:28 UTC
Per the javadoc at http://docs.oracle.com/javaee/7/api/javax/el/ELProcessor.html it specifies that defineFunction(String prefix, String function, String className, String method) should support method names (without parenthesis) and method signatures, it gives an example of "int sum(int, int)"

The code I was using from 8.0.8 does not properly parse this example, in the javax.el.ElProcessor.MethodSignature class the constructor first incorrectly cuts off the last character of the method name by using "methodName.substring(0, paramIndex -1)" second it continues to include the return type in the name.

A better but not to java specification version would be to replace the following code

int paramIndex = methodName.indexOf('(');

if (paramIndex == -1) {
    name = methodName.trim();
    parameterTypeNames = null;
} else {
    name = methodName.substring(0, paramIndex -1).trim();


with:

int paramIndex = methodName.indexOf('(');

if (paramIndex == -1) {
    name = methodName.trim();
    parameterTypeNames = null;
} else {
    String tmpName = methodName.substring(0, paramIndex).trim();
    int lastWhitespaceIndex = tmpName.lastIndexOf(' ');
    name = lastWhitespaceIndex > -1 ? tmpName.substring(lastWhitespaceIndex + 1) : tmpName;


This allows the MethodSignature class to return a proper method name that then can be used in the ELProcessor.defineFunction method to compare the reflected classes method names.
Comment 1 Mark Thomas 2014-06-18 10:35:49 UTC
Thanks for the report. This has been fixed in 8.0.x and will be included in 8.0.9 onwards.