~ubuntu-branches/ubuntu/trusty/tomcat7/trusty-security

« back to all changes in this revision

Viewing changes to java/org/apache/el/util/ReflectionUtil.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2012-06-07 22:43:21 UTC
  • mfrom: (11.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20120607224321-cfev8j681yueyov3
Tags: 7.0.27-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import java.util.Map;
24
24
import java.util.Set;
25
25
 
 
26
import javax.el.ELException;
26
27
import javax.el.MethodNotFoundException;
27
28
 
 
29
import org.apache.el.lang.ELSupport;
 
30
 
28
31
 
29
32
/**
30
33
 * Utilities for Managing Serialization and Reflection
31
34
 * 
32
35
 * @author Jacob Hookom [jacob@hookom.net]
33
 
 * @version $Id: ReflectionUtil.java 1050683 2010-12-18 17:43:41Z markt $
 
36
 * @version $Id: ReflectionUtil.java 1304933 2012-03-24 21:33:47Z markt $
34
37
 */
35
38
public class ReflectionUtil {
36
39
 
106
109
     * @param base the object that owns the method
107
110
     * @param property the name of the method
108
111
     * @param paramTypes the parameter types to use
 
112
     * @param paramValues the parameter values
109
113
     * @return the method specified
110
114
     * @throws MethodNotFoundException
111
115
     */
112
116
    @SuppressWarnings("null")
113
117
    public static Method getMethod(Object base, Object property,
114
 
            Class<?>[] paramTypes) throws MethodNotFoundException {
 
118
            Class<?>[] paramTypes, Object[] paramValues)
 
119
            throws MethodNotFoundException {
115
120
        if (base == null || property == null) {
116
121
            throw new MethodNotFoundException(MessageFactory.get(
117
122
                    "error.method.notfound", base, property,
163
168
                    Class<?> varType = mParamTypes[i].getComponentType();
164
169
                    for (int j = i; j < paramCount; j++) {
165
170
                        if (!isAssignableFrom(paramTypes[j], varType)) {
166
 
                            break;
 
171
                            if (paramValues == null) {
 
172
                                noMatch = true;
 
173
                                break;
 
174
                            } else {
 
175
                                if (!isCoercibleFrom(paramValues[j], varType)) {
 
176
                                    noMatch = true;
 
177
                                    break;
 
178
                                }
 
179
                            }
167
180
                        }
168
181
                        // Don't treat a varArgs match as an exact match, it can
169
182
                        // lead to a varArgs method matching when the result
170
183
                        // should be ambiguous
171
184
                    }
172
185
                } else if (!isAssignableFrom(paramTypes[i], mParamTypes[i])) {
173
 
                    noMatch = true;
174
 
                    break;
 
186
                    if (paramValues == null) {
 
187
                        noMatch = true;
 
188
                        break;
 
189
                    } else {
 
190
                        if (!isCoercibleFrom(paramValues[i], mParamTypes[i])) {
 
191
                            noMatch = true;
 
192
                            break;
 
193
                        }
 
194
                    }
175
195
                }
176
196
            }
177
197
            if (noMatch) {
299
319
        return targetClass.isAssignableFrom(src);
300
320
    }
301
321
 
 
322
    private static boolean isCoercibleFrom(Object src, Class<?> target) {
 
323
        // TODO: This isn't pretty but it works. Significant refactoring would
 
324
        //       be required to avoid the exception.
 
325
        try {
 
326
            ELSupport.coerceToType(src, target);
 
327
        } catch (ELException e) {
 
328
            return false;
 
329
        }
 
330
        return true;
 
331
    }
 
332
 
302
333
    protected static final String paramString(Class<?>[] types) {
303
334
        if (types != null) {
304
335
            StringBuilder sb = new StringBuilder();