Distinguish between different bridge method types
Add BridgeMethodResolver#isJava6VisibilityBridgeMethodPair to distinguish between (a) bridge methods introduced in Java 6 to compensate for inheriting public methods from non-public superclasses and (b) bridge methods that have existed since Java 5 to accommodate return type covariance and generic parameters. In the former case, annotations should be looked up from the original bridged method (SPR-7900). In the latter, the annotation should be looked up against the bridge method itself (SPR-8660). As noted in the Javadoc for the new method, see http://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html for a useful description of the various types of bridge methods, as well as http://bugs.sun.com/view_bug.do?bug_id=6342411, the bug fixed in Java 6 resulting in the introduction of 'visibility bridge methods'. Issue: SPR-8660, SPR-7900
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -210,4 +211,22 @@ public abstract class BridgeMethodResolver {
|
||||
return ReflectionUtils.findMethod(type, bridgeMethod.getName(), bridgeMethod.getParameterTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 http://bugs.sun.com/view_bug.do?bug_id=6342411.
|
||||
* See also http://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html
|
||||
* @return whether signatures match as described
|
||||
*/
|
||||
public static boolean isJava6VisibilityBridgeMethodPair(Method bridgeMethod, Method bridgedMethod) {
|
||||
Assert.isTrue(bridgeMethod != null);
|
||||
Assert.isTrue(bridgedMethod != null);
|
||||
if (bridgeMethod == bridgedMethod) {
|
||||
return true;
|
||||
}
|
||||
return Arrays.equals(bridgeMethod.getParameterTypes(), bridgedMethod.getParameterTypes())
|
||||
&& bridgeMethod.getReturnType().equals(bridgedMethod.getReturnType());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user