Skip to content

Commit c5a33d6

Browse files
committed
TypeVariablesVariableResolver compares variables by full equality again
Issue: SPR-16456
1 parent 30f6e44 commit c5a33d6

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,9 @@ public TypeVariablesVariableResolver(TypeVariable<?>[] variables, ResolvableType
14681468
@Nullable
14691469
public ResolvableType resolveVariable(TypeVariable<?> variable) {
14701470
for (int i = 0; i < this.variables.length; i++) {
1471-
if (ObjectUtils.nullSafeEquals(this.variables[i].getName(), variable.getName())) {
1471+
TypeVariable<?> v1 = SerializableTypeWrapper.unwrap(this.variables[i]);
1472+
TypeVariable<?> v2 = SerializableTypeWrapper.unwrap(variable);
1473+
if (ObjectUtils.nullSafeEquals(v1, v2)) {
14721474
return this.generics[i];
14731475
}
14741476
}

spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.concurrent.Callable;
4444

4545
import org.hamcrest.Matchers;
46+
import org.junit.Ignore;
4647
import org.junit.Rule;
4748
import org.junit.Test;
4849
import org.junit.rules.ExpectedException;
@@ -1337,6 +1338,7 @@ public void testSpr14648() throws Exception {
13371338
assertTrue(setClass.isAssignableFrom(fromReturnType));
13381339
}
13391340

1341+
@Ignore
13401342
@Test
13411343
public void testSpr16456() throws Exception {
13421344
ResolvableType genericType = ResolvableType.forField(

spring-web/src/test/java/org/springframework/web/method/ResolvableMethod.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -77,7 +77,6 @@
7777
* return type, possibly with or without an annotation.
7878
*
7979
* <pre>
80-
*
8180
* import static org.springframework.web.method.ResolvableMethod.on;
8281
* import static org.springframework.web.method.MvcAnnotationPredicates.requestMapping;
8382
*
@@ -102,7 +101,6 @@
102101
* of methods with a wide array of argument types and parameter annotations.
103102
*
104103
* <pre>
105-
*
106104
* import static org.springframework.web.method.MvcAnnotationPredicates.requestParam;
107105
*
108106
* ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
@@ -118,7 +116,6 @@
118116
* Locate a method by invoking it through a proxy of the target handler:
119117
*
120118
* <pre>
121-
*
122119
* ResolvableMethod.on(TestController.class).mockCall(o -> o.handle(null)).method();
123120
* </pre>
124121
*
@@ -130,9 +127,7 @@ public class ResolvableMethod {
130127

131128
private static final SpringObjenesis objenesis = new SpringObjenesis();
132129

133-
private static final ParameterNameDiscoverer nameDiscoverer =
134-
new LocalVariableTableParameterNameDiscoverer();
135-
130+
private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
136131

137132
private final Method method;
138133

@@ -361,16 +356,14 @@ public Builder<T> returning(ResolvableType returnType) {
361356
/**
362357
* Build a {@code ResolvableMethod} from the provided filters which must
363358
* resolve to a unique, single method.
364-
*
365359
* <p>See additional resolveXxx shortcut methods going directly to
366360
* {@link Method} or return type parameter.
367-
*
368361
* @throws IllegalStateException for no match or multiple matches
369362
*/
370363
public ResolvableMethod build() {
371364
Set<Method> methods = MethodIntrospector.selectMethods(this.objectClass, this::isMatch);
372-
Assert.state(!methods.isEmpty(), "No matching method: " + this);
373-
Assert.state(methods.size() == 1, "Multiple matching methods: " + this + formatMethods(methods));
365+
Assert.state(!methods.isEmpty(), () -> "No matching method: " + this);
366+
Assert.state(methods.size() == 1, () -> "Multiple matching methods: " + this + formatMethods(methods));
374367
return new ResolvableMethod(methods.iterator().next());
375368
}
376369

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -259,7 +259,7 @@ public void handleReturnValueEtag() throws Exception {
259259
assertConditionalResponse(exchange, HttpStatus.NOT_MODIFIED, null, etagValue, Instant.MIN);
260260
}
261261

262-
@Test // SPR-14559
262+
@Test // SPR-14559
263263
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
264264
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch("unquoted"));
265265

@@ -313,9 +313,8 @@ public void handleReturnValueChangedETagAndLastModified() throws Exception {
313313
assertConditionalResponse(exchange, HttpStatus.OK, "body", newEtag, oneMinAgo);
314314
}
315315

316-
@Test // SPR-14877
316+
@Test // SPR-14877
317317
public void handleMonoWithWildcardBodyType() throws Exception {
318-
319318
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
320319
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
321320

@@ -328,9 +327,8 @@ public void handleMonoWithWildcardBodyType() throws Exception {
328327
assertResponseBody(exchange, "body");
329328
}
330329

331-
@Test // SPR-14877
330+
@Test // SPR-14877
332331
public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
333-
334332
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
335333
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
336334

@@ -345,7 +343,6 @@ public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
345343

346344

347345
private void testHandle(Object returnValue, MethodParameter returnType) {
348-
349346
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
350347
HandlerResult result = handlerResult(returnValue, returnType);
351348
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));

0 commit comments

Comments
 (0)