Skip to content

Commit 1e88870

Browse files
committed
BridgeMethodResolver properly handles bridge methods in interfaces
Issue: SPR-9330
1 parent 1bca2c0 commit 1e88870

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

org.springframework.core/src/main/java/org/springframework/core/BridgeMethodResolver.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28-
import org.springframework.util.Assert;
2928
import org.springframework.util.ClassUtils;
3029
import org.springframework.util.ReflectionUtils;
3130

@@ -91,7 +90,7 @@ public static Method findBridgedMethod(Method bridgeMethod) {
9190
* Searches for the bridged method in the given candidates.
9291
* @param candidateMethods the List of candidate Methods
9392
* @param bridgeMethod the bridge method
94-
* @return the bridged method, or <code>null</code> if none found
93+
* @return the bridged method, or {@code null} if none found
9594
*/
9695
private static Method searchCandidates(List<Method> candidateMethods, Method bridgeMethod) {
9796
if (candidateMethods.isEmpty()) {
@@ -114,7 +113,7 @@ else if (previousMethod != null) {
114113
}
115114

116115
/**
117-
* Returns <code>true</code> if the supplied '<code>candidateMethod</code>' can be
116+
* Returns {@code true} if the supplied '{@code candidateMethod}' can be
118117
* consider a validate candidate for the {@link Method} that is {@link Method#isBridge() bridged}
119118
* by the supplied {@link Method bridge Method}. This method performs inexpensive
120119
* checks and can be used quickly filter for a set of possible matches.
@@ -145,7 +144,7 @@ static boolean isBridgeMethodFor(Method bridgeMethod, Method candidateMethod, Ma
145144
private static Method findGenericDeclaration(Method bridgeMethod) {
146145
// Search parent types for method that has same signature as bridge.
147146
Class superclass = bridgeMethod.getDeclaringClass().getSuperclass();
148-
while (!Object.class.equals(superclass)) {
147+
while (superclass != null && !Object.class.equals(superclass)) {
149148
Method method = searchForMatch(superclass, bridgeMethod);
150149
if (method != null && !method.isBridge()) {
151150
return method;
@@ -166,10 +165,10 @@ private static Method findGenericDeclaration(Method bridgeMethod) {
166165
}
167166

168167
/**
169-
* Returns <code>true</code> if the {@link Type} signature of both the supplied
168+
* Returns {@code true} if the {@link Type} signature of both the supplied
170169
* {@link Method#getGenericParameterTypes() generic Method} and concrete {@link Method}
171170
* are equal after resolving all {@link TypeVariable TypeVariables} using the supplied
172-
* TypeVariable Map, otherwise returns <code>false</code>.
171+
* TypeVariable Map, otherwise returns {@code false}.
173172
*/
174173
private static boolean isResolvedTypeMatch(
175174
Method genericMethod, Method candidateMethod, Map<TypeVariable, Type> typeVariableMap) {
@@ -205,7 +204,7 @@ private static boolean isResolvedTypeMatch(
205204
/**
206205
* If the supplied {@link Class} has a declared {@link Method} whose signature matches
207206
* that of the supplied {@link Method}, then this matching {@link Method} is returned,
208-
* otherwise <code>null</code> is returned.
207+
* otherwise {@code null} is returned.
209208
*/
210209
private static Method searchForMatch(Class type, Method bridgeMethod) {
211210
return ReflectionUtils.findMethod(type, bridgeMethod.getName(), bridgeMethod.getParameterTypes());
@@ -219,8 +218,6 @@ private static Method searchForMatch(Class type, Method bridgeMethod) {
219218
* @return whether signatures match as described
220219
*/
221220
public static boolean isVisibilityBridgeMethodPair(Method bridgeMethod, Method bridgedMethod) {
222-
Assert.isTrue(bridgeMethod != null);
223-
Assert.isTrue(bridgedMethod != null);
224221
if (bridgeMethod == bridgedMethod) {
225222
return true;
226223
}

0 commit comments

Comments
 (0)