MCPcopy Index your code
hub / github.com/apache/tomcat / resolveAmbiguousWrapper

Method resolveAmbiguousWrapper

java/jakarta/el/Util.java:303–361  ·  view source on GitHub ↗
(Set<Wrapper<T>> candidates, Class<?>[] paramTypes)

Source from the content-addressed store, hash-verified

301 * This method duplicates code in org.apache.el.util.ReflectionUtil. When making changes keep the code in sync.
302 */
303 private static <T> Wrapper<T> resolveAmbiguousWrapper(Set<Wrapper<T>> candidates, Class<?>[] paramTypes) {
304 // Identify which parameter isn't an exact match
305 Wrapper<T> w = candidates.iterator().next();
306
307 int nonMatchIndex = 0;
308 Class<?> nonMatchClass = null;
309
310 for (int i = 0; i < paramTypes.length; i++) {
311 if (w.getParameterTypes()[i] != paramTypes[i]) {
312 nonMatchIndex = i;
313 nonMatchClass = paramTypes[i];
314 break;
315 }
316 }
317
318 if (nonMatchClass == null) {
319 // Null will always be ambiguous
320 return null;
321 }
322
323 for (Wrapper<T> c : candidates) {
324 if (c.getParameterTypes()[nonMatchIndex] == paramTypes[nonMatchIndex]) {
325 // Methods have different non-matching parameters
326 // Result is ambiguous
327 return null;
328 }
329 }
330
331 // Can't be null
332 Class<?> superClass = nonMatchClass.getSuperclass();
333 while (superClass != null) {
334 for (Wrapper<T> c : candidates) {
335 if (c.getParameterTypes()[nonMatchIndex].equals(superClass)) {
336 // Found a match
337 return c;
338 }
339 }
340 superClass = superClass.getSuperclass();
341 }
342
343 // Treat instances of Number as a special case
344 Wrapper<T> match = null;
345 if (Number.class.isAssignableFrom(nonMatchClass)) {
346 for (Wrapper<T> c : candidates) {
347 Class<?> candidateType = c.getParameterTypes()[nonMatchIndex];
348 if (Number.class.isAssignableFrom(candidateType) || candidateType.isPrimitive()) {
349 if (match == null) {
350 match = c;
351 } else {
352 // Match still ambiguous
353 match = null;
354 break;
355 }
356 }
357 }
358 }
359
360 return match;

Callers 1

findWrapperMethod · 0.95

Calls 6

isPrimitiveMethod · 0.80
nextMethod · 0.65
equalsMethod · 0.65
iteratorMethod · 0.45
getParameterTypesMethod · 0.45
isAssignableFromMethod · 0.45

Tested by

no test coverage detected