Top Description Fields Constructors Methods
org.springframework.core

public final Class BridgeMethodResolver

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, .Type, java.util.ArrayList, .Arrays, .List, .Map, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ConcurrentReferenceHashMap, .ReflectionUtils, .ReflectionUtils.MethodFilter

Helper for resolving synthetic bridge Methods to the Method being bridged.

Given a synthetic bridge Method returns the Method being bridged. A bridge method may be created by the compiler when extending a parameterized type whose methods have parameterized arguments. During runtime invocation the bridge Method may be invoked and/or used via reflection. When attempting to locate annotations on Methods, it is wise to check for bridge Methods as appropriate and find the bridged Method.

See The Java Language Specification for more details on the use of bridge methods.

Authors
Rob Harrop, Juergen Hoeller, Phillip Webb
Since
2.0

Field Summary

Modifier and TypeField and Description
private static final Map<Object, Method>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Method

Returns:

the original method (either the bridged method or the passed-in method if no more specific one could be found)
findBridgedMethod
(Method
the method to introspect against its declaring class
bridgeMethod
)

Find the local original method for the supplied bridge Method.

private static Method
findGenericDeclaration(Method bridgeMethod)

Searches for the generic Method declaration whose erased signature matches that of the supplied bridge method.

public static Method

Returns:

the original method (either the bridged method or the passed-in method if no more specific one could be found)
getMostSpecificMethod
(Method
the method to introspect against the given target class
bridgeMethod
,
Class<?>
the target class to find methods on
targetClass
)

Determine the most specific method for the supplied bridge Method in the given class hierarchy, even if not available on the local declaring class.

private static boolean
isBridgedCandidateFor(Method candidateMethod, Method bridgeMethod)

Returns true if the supplied 'candidateMethod' can be considered a valid candidate for the Method that is bridged by the supplied bridge Method.

pack-priv static boolean
isBridgeMethodFor(Method bridgeMethod, Method candidateMethod, Class<?> declaringClass)

Determines whether the bridge Method is the bridge for the supplied candidate Method.

private static boolean
isResolvedTypeMatch(Method genericMethod, Method candidateMethod, Class<?> declaringClass)

Returns true if the Type signature of both the supplied generic Method and concrete Method are equal after resolving all types against the declaringType, otherwise returns false.

public static boolean

Returns:

whether signatures match as described
isVisibilityBridgeMethodPair
(Method bridgeMethod, Method bridgedMethod)

Compare the signatures of the bridge method and the method which it bridges.

private static Method
resolveBridgeMethod(Method bridgeMethod, Class<?> targetClass)

private static Method

Returns:

the bridged method, or null if none found
searchCandidates
(List<Method>
the List of candidate Methods
candidateMethods
,
Method
the bridge method
bridgeMethod
)

Searches for the bridged method in the given candidates.

private static Method
searchForMatch(Class<?> type, Method bridgeMethod)

If the supplied Class has a declared Method whose signature matches that of the supplied Method, then this matching Method is returned, otherwise null is returned.

private static Method
searchInterfaces(Class<?>[] interfaces, Method bridgeMethod)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private static final Map<Object, Method> cache

Constructor Detail

BridgeMethodResolverback to summary
private BridgeMethodResolver()

Method Detail

findBridgedMethodback to summary
public static Method findBridgedMethod(Method bridgeMethod)

Find the local original method for the supplied bridge Method.

It is safe to call this method passing in a non-bridge Method instance. In such a case, the supplied Method instance is returned directly to the caller. Callers are not required to check for bridging before calling this method.

Parameters
bridgeMethod:Method

the method to introspect against its declaring class

Returns:Method

the original method (either the bridged method or the passed-in method if no more specific one could be found)

See Also
getMostSpecificMethod(Method, Class)
findGenericDeclarationback to summary
private static Method findGenericDeclaration(Method bridgeMethod)

Searches for the generic Method declaration whose erased signature matches that of the supplied bridge method.

Annotations
@Nullable
Exceptions
IllegalStateException:
if the generic declaration cannot be found
getMostSpecificMethodback to summary
public static Method getMostSpecificMethod(Method bridgeMethod, Class<?> targetClass)

Determine the most specific method for the supplied bridge Method in the given class hierarchy, even if not available on the local declaring class.

This is effectively a combination of ClassUtils#getMostSpecificMethod and findBridgedMethod, resolving the original method even if no bridge method has been generated at the same class hierarchy level (a known difference between the Eclipse compiler and regular javac).

Parameters
bridgeMethod:Method

the method to introspect against the given target class

targetClass:Class<?>

the target class to find methods on

Returns:Method

the original method (either the bridged method or the passed-in method if no more specific one could be found)

Since
6.1.3
See Also
findBridgedMethod, org.springframework.util.ClassUtils#getMostSpecificMethod
isBridgedCandidateForback to summary
private static boolean isBridgedCandidateFor(Method candidateMethod, Method bridgeMethod)

Returns true if the supplied 'candidateMethod' can be considered a valid candidate for the Method that is bridged by the supplied bridge Method. This method performs inexpensive checks and can be used to quickly filter for a set of possible matches.

isBridgeMethodForback to summary
pack-priv static boolean isBridgeMethodFor(Method bridgeMethod, Method candidateMethod, Class<?> declaringClass)

Determines whether the bridge Method is the bridge for the supplied candidate Method.

isResolvedTypeMatchback to summary
private static boolean isResolvedTypeMatch(Method genericMethod, Method candidateMethod, Class<?> declaringClass)

Returns true if the Type signature of both the supplied generic Method and concrete Method are equal after resolving all types against the declaringType, otherwise returns false.

isVisibilityBridgeMethodPairback to summary
public static boolean isVisibilityBridgeMethodPair(Method bridgeMethod, Method bridgedMethod)

Compare the signatures of the bridge method and the method which it bridges. If the parameter and return types are the same, it is a 'visibility' bridge method introduced in Java 6 to fix https://bugs.openjdk.org/browse/JDK-6342411. See also https://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html

Returns:boolean

whether signatures match as described

resolveBridgeMethodback to summary
private static Method resolveBridgeMethod(Method bridgeMethod, Class<?> targetClass)
searchCandidatesback to summary
private static Method searchCandidates(List<Method> candidateMethods, Method bridgeMethod)

Searches for the bridged method in the given candidates.

Parameters
candidateMethods:List<Method>

the List of candidate Methods

bridgeMethod:Method

the bridge method

Returns:Method

the bridged method, or null if none found

Annotations
@Nullable
searchForMatchback to summary
private static Method searchForMatch(Class<?> type, Method bridgeMethod)

If the supplied Class has a declared Method whose signature matches that of the supplied Method, then this matching Method is returned, otherwise null is returned.

Annotations
@Nullable
searchInterfacesback to summary
private static Method searchInterfaces(Class<?>[] interfaces, Method bridgeMethod)
Annotations
@Nullable