Skip to content

Commit 8ef557d

Browse files
committed
Merge branch '5.1.x'
2 parents 5e15bbf + b2c5659 commit 8ef557d

File tree

16 files changed

+87
-43
lines changed

16 files changed

+87
-43
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ext {
3939
junit5Version = "5.5.1"
4040
kotlinVersion = "1.3.41"
4141
log4jVersion = "2.12.0"
42-
nettyVersion = "4.1.37.Final"
42+
nettyVersion = "4.1.38.Final"
4343
reactorVersion = "Dysprosium-M3"
4444
rsocketVersion = "0.12.2-RC4"
4545
rxjavaVersion = "1.3.8"
@@ -149,7 +149,7 @@ configure(allprojects) { project ->
149149
}
150150

151151
checkstyle {
152-
toolVersion = "8.22"
152+
toolVersion = "8.23"
153153
configDir = rootProject.file("src/checkstyle")
154154
}
155155

spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public boolean equals(@Nullable Object other) {
430430

431431
@Override
432432
public int hashCode() {
433-
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass);
433+
return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass));
434434
}
435435

436436

spring-context/src/main/java/org/springframework/validation/ObjectError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -144,7 +144,7 @@ public boolean equals(@Nullable Object other) {
144144

145145
@Override
146146
public int hashCode() {
147-
return super.hashCode() * 29 + getObjectName().hashCode();
147+
return (29 * super.hashCode() + getObjectName().hashCode());
148148
}
149149

150150
@Override

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -39,6 +39,7 @@
3939
import org.springframework.lang.Nullable;
4040
import org.springframework.util.Assert;
4141
import org.springframework.util.ClassUtils;
42+
import org.springframework.util.ObjectUtils;
4243

4344
/**
4445
* Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method}
@@ -61,14 +62,15 @@ public class MethodParameter {
6162

6263
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
6364

65+
6466
private final Executable executable;
6567

6668
private final int parameterIndex;
6769

6870
@Nullable
6971
private volatile Parameter parameter;
7072

71-
private int nestingLevel = 1;
73+
private int nestingLevel;
7274

7375
/** Map from Integer level to Integer type index. */
7476
@Nullable
@@ -662,12 +664,16 @@ public boolean equals(@Nullable Object other) {
662664
return false;
663665
}
664666
MethodParameter otherParam = (MethodParameter) other;
665-
return (this.parameterIndex == otherParam.parameterIndex && getExecutable().equals(otherParam.getExecutable()));
667+
return (this.containingClass == otherParam.containingClass &&
668+
ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) &&
669+
this.nestingLevel == otherParam.nestingLevel &&
670+
this.parameterIndex == otherParam.parameterIndex &&
671+
this.executable.equals(otherParam.executable));
666672
}
667673

668674
@Override
669675
public int hashCode() {
670-
return (getExecutable().hashCode() * 31 + this.parameterIndex);
676+
return (31 * this.executable.hashCode() + this.parameterIndex);
671677
}
672678

673679
@Override

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.Target;
2323
import java.lang.reflect.Constructor;
2424
import java.lang.reflect.Method;
25+
import java.util.ArrayList;
2526
import java.util.concurrent.Callable;
2627

2728
import org.junit.Before;
@@ -149,6 +150,44 @@ public void genericConstructorParameterInInnerClass() throws Exception {
149150
assertThat(methodParameter.getGenericParameterType()).isEqualTo(ResolvableType.forClassWithGenerics(Callable.class, Integer.class).getType());
150151
}
151152

153+
@Test
154+
public void multipleResolveParameterTypeCalls() throws Exception {
155+
Method method = ArrayList.class.getMethod("get", int.class);
156+
MethodParameter methodParameter = MethodParameter.forExecutable(method, -1);
157+
assertEquals(Object.class, methodParameter.getParameterType());
158+
GenericTypeResolver.resolveParameterType(methodParameter, StringList.class);
159+
assertEquals(String.class, methodParameter.getParameterType());
160+
GenericTypeResolver.resolveParameterType(methodParameter, IntegerList.class);
161+
assertEquals(Integer.class, methodParameter.getParameterType());
162+
}
163+
164+
@Test
165+
public void equalsAndHashCodeConsidersContainingClass() throws Exception {
166+
Method method = ArrayList.class.getMethod("get", int.class);
167+
MethodParameter m1 = MethodParameter.forExecutable(method, -1);
168+
MethodParameter m2 = MethodParameter.forExecutable(method, -1);
169+
MethodParameter m3 = MethodParameter.forExecutable(method, -1).nested();
170+
assertEquals(m1, m2);
171+
assertNotEquals(m1, m3);
172+
assertEquals(m1.hashCode(), m2.hashCode());
173+
}
174+
175+
@Test
176+
public void equalsAndHashCodeConsidersNesting() throws Exception {
177+
Method method = ArrayList.class.getMethod("get", int.class);
178+
MethodParameter m1 = MethodParameter.forExecutable(method, -1);
179+
GenericTypeResolver.resolveParameterType(m1, StringList.class);
180+
MethodParameter m2 = MethodParameter.forExecutable(method, -1);
181+
GenericTypeResolver.resolveParameterType(m2, StringList.class);
182+
MethodParameter m3 = MethodParameter.forExecutable(method, -1);
183+
GenericTypeResolver.resolveParameterType(m3, IntegerList.class);
184+
MethodParameter m4 = MethodParameter.forExecutable(method, -1);
185+
assertEquals(m1, m2);
186+
assertNotEquals(m1, m3);
187+
assertNotEquals(m1, m4);
188+
assertEquals(m1.hashCode(), m2.hashCode());
189+
}
190+
152191

153192
public int method(String p1, long p2) {
154193
return 42;
@@ -173,4 +212,12 @@ public InnerClass(@Param String s, Callable<Integer> i) {
173212
private @interface Param {
174213
}
175214

215+
@SuppressWarnings("serial")
216+
private static class StringList extends ArrayList<String> {
217+
}
218+
219+
@SuppressWarnings("serial")
220+
private static class IntegerList extends ArrayList<Integer> {
221+
}
222+
176223
}

spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public boolean equals(@Nullable Object other) {
591591

592592
@Override
593593
public int hashCode() {
594-
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector);
594+
return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector));
595595
}
596596

597597
@Override

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -110,9 +110,8 @@ public boolean supportsParameter(MethodParameter parameter) {
110110
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
111111
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
112112
if (resolver == null) {
113-
throw new IllegalStateException(
114-
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." +
115-
" supportsParameter should be called first.");
113+
throw new IllegalArgumentException("Unsupported parameter type [" +
114+
parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
116115
}
117116
return resolver.resolveArgument(parameter, message);
118117
}

spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java

Lines changed: 2 additions & 2 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-2019 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.
@@ -178,7 +178,7 @@ public boolean equals(@Nullable Object other) {
178178
*/
179179
@Override
180180
public int hashCode() {
181-
return super.hashCode() * 31 + this.resourceBasePath.hashCode();
181+
return (31 * super.hashCode() + this.resourceBasePath.hashCode());
182182
}
183183

184184
/**

spring-web/src/main/java/org/springframework/http/ResponseEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -169,7 +169,7 @@ public boolean equals(@Nullable Object other) {
169169

170170
@Override
171171
public int hashCode() {
172-
return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.status));
172+
return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.status));
173173
}
174174

175175
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public boolean setStatusCode(@Nullable HttpStatus status) {
108108
@Override
109109
@Nullable
110110
public HttpStatus getStatusCode() {
111-
return this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null;
111+
return (this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null);
112112
}
113113

114114
/**

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -19,7 +19,6 @@
1919
import java.nio.file.Path;
2020

2121
import io.netty.buffer.ByteBuf;
22-
import io.netty.handler.codec.http.HttpResponseStatus;
2322
import io.netty.handler.codec.http.cookie.Cookie;
2423
import io.netty.handler.codec.http.cookie.DefaultCookie;
2524
import org.reactivestreams.Publisher;
@@ -62,14 +61,9 @@ public <T> T getNativeResponse() {
6261
}
6362

6463
@Override
65-
@SuppressWarnings("ConstantConditions")
6664
public HttpStatus getStatusCode() {
6765
HttpStatus httpStatus = super.getStatusCode();
68-
if (httpStatus == null) {
69-
HttpResponseStatus status = this.response.status();
70-
httpStatus = status != null ? HttpStatus.resolve(status.code()) : null;
71-
}
72-
return httpStatus;
66+
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.status().code()));
7367
}
7468

7569

spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -100,7 +100,7 @@ public <T> T getNativeResponse() {
100100
@Override
101101
public HttpStatus getStatusCode() {
102102
HttpStatus httpStatus = super.getStatusCode();
103-
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus());
103+
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus()));
104104
}
105105

106106
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -69,8 +69,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
6969
}
7070

7171
private static HttpHeaders createHeaders(HttpServerExchange exchange) {
72-
UndertowHeadersAdapter headersMap =
73-
new UndertowHeadersAdapter(exchange.getResponseHeaders());
72+
UndertowHeadersAdapter headersMap = new UndertowHeadersAdapter(exchange.getResponseHeaders());
7473
return new HttpHeaders(headersMap);
7574
}
7675

@@ -84,7 +83,7 @@ public <T> T getNativeResponse() {
8483
@Override
8584
public HttpStatus getStatusCode() {
8685
HttpStatus httpStatus = super.getStatusCode();
87-
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode());
86+
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()));
8887
}
8988

9089

spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -119,9 +119,8 @@ public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC
119119

120120
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
121121
if (resolver == null) {
122-
throw new IllegalArgumentException(
123-
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." +
124-
" supportsParameter should be called first.");
122+
throw new IllegalArgumentException("Unsupported parameter type [" +
123+
parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
125124
}
126125
return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
127126
}

spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodArgumentResolverCompositeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class HandlerMethodArgumentResolverCompositeTests {
4141

4242

4343
@Before
44-
public void setUp() throws Exception {
44+
public void setup() throws Exception {
4545
this.resolverComposite = new HandlerMethodArgumentResolverComposite();
4646

4747
Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class);
@@ -51,7 +51,7 @@ public void setUp() throws Exception {
5151

5252

5353
@Test
54-
public void supportsParameter() {
54+
public void supportsParameter() throws Exception {
5555
this.resolverComposite.addResolver(new StubArgumentResolver(Integer.class));
5656

5757
assertThat(this.resolverComposite.supportsParameter(paramInt)).isTrue();

spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodReturnValueHandlerCompositeTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
/**
3232
* Test fixture with {@link HandlerMethodReturnValueHandlerComposite}.
33+
*
3334
* @author Rossen Stoyanchev
3435
*/
3536
@SuppressWarnings("unused")
@@ -47,8 +48,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {
4748

4849

4950
@Before
50-
public void setUp() throws Exception {
51-
51+
public void setup() throws Exception {
5252
this.integerType = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1);
5353
this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);
5454

@@ -61,6 +61,7 @@ public void setUp() throws Exception {
6161
mavContainer = new ModelAndViewContainer();
6262
}
6363

64+
6465
@Test
6566
public void supportsReturnType() throws Exception {
6667
assertThat(this.handlers.supportsReturnType(this.integerType)).isTrue();
@@ -84,9 +85,8 @@ public void handleReturnValueWithMultipleHandlers() throws Exception {
8485
verifyNoMoreInteractions(anotherIntegerHandler);
8586
}
8687

87-
@Test // SPR-13083
88+
@Test // SPR-13083
8889
public void handleReturnValueWithAsyncHandler() throws Exception {
89-
9090
Promise<Integer> promise = new Promise<>();
9191
MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1);
9292

0 commit comments

Comments
 (0)