Skip to content

Commit 39cd316

Browse files
committed
Polishing
1 parent ca2b3c1 commit 39cd316

File tree

8 files changed

+43
-82
lines changed

8 files changed

+43
-82
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ class CglibAopProxy implements AopProxy, Serializable {
9494
private static final int INVOKE_HASHCODE = 6;
9595

9696

97+
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
98+
99+
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
100+
"kotlinx.coroutines.reactor.MonoKt", CglibAopProxy.class.getClassLoader());
101+
97102
/** Logger available to subclasses; static to optimize serialization. */
98103
protected static final Log logger = LogFactory.getLog(CglibAopProxy.class);
99104

100105
/** Keeps track of the Classes that we have validated for final methods. */
101106
private static final Map<Class<?>, Boolean> validatedClasses = new WeakHashMap<>();
102107

103-
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
104-
105-
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
106-
CglibAopProxy.class.getClassLoader());;
107-
108108

109109
/** The configuration used to configure this proxy. */
110110
protected final AdvisedSupport advised;

spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
7575

7676
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
7777

78-
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
79-
JdkDynamicAopProxy.class.getClassLoader());;
78+
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
79+
"kotlinx.coroutines.reactor.MonoKt", JdkDynamicAopProxy.class.getClassLoader());
8080

8181
/** We use a static Log to avoid serialization issues. */
8282
private static final Log logger = LogFactory.getLog(JdkDynamicAopProxy.class);

spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
*/
6565
public abstract class AopUtils {
6666

67-
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
68-
AopUtils.class.getClassLoader());;
67+
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
68+
"kotlinx.coroutines.reactor.MonoKt", AopUtils.class.getClassLoader());
69+
6970

7071
/**
7172
* Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
@@ -349,8 +350,8 @@ public static Object invokeJoinpointUsingReflection(@Nullable Object target, Met
349350
// Use reflection to invoke the method.
350351
try {
351352
ReflectionUtils.makeAccessible(method);
352-
return coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
353-
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args);
353+
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
354+
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args));
354355
}
355356
catch (InvocationTargetException ex) {
356357
// Invoked method threw a checked exception.

spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
*/
3636
class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
3737

38-
@Nullable
3938
@Override
39+
@Nullable
4040
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
4141
Class<?> beanClass = registeredBean.getBeanClass();
4242
if (KotlinDetector.isKotlinType(beanClass)) {
@@ -45,6 +45,7 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
4545
return null;
4646
}
4747

48+
4849
private static class AotContribution implements BeanRegistrationAotContribution {
4950

5051
private final Class<?> beanClass;

spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void getHeaders() {
124124
assertThat(headers).as("No HttpHeaders returned").isNotNull();
125125
assertThat(headers.containsKey(headerName)).as("Invalid headers returned").isTrue();
126126
List<String> headerValues = headers.get(headerName);
127+
assertThat(headerValues).as("No header values returned").isNotNull();
127128
assertThat(headerValues.size()).as("Invalid header values returned").isEqualTo(2);
128129
assertThat(headerValues.contains(headerValue1)).as("Invalid header values returned").isTrue();
129130
assertThat(headerValues.contains(headerValue2)).as("Invalid header values returned").isTrue();
@@ -150,7 +151,7 @@ void getHeadersWithEmptyContentTypeAndEncoding() {
150151
assertThat(headers.getContentType()).isNull();
151152
}
152153

153-
@Test // gh-27957
154+
@Test // gh-27957
154155
void getHeadersWithWildcardContentType() {
155156
mockRequest.setContentType("*/*");
156157
mockRequest.removeHeader("Content-Type");
@@ -166,7 +167,7 @@ void getBody() throws IOException {
166167
assertThat(result).as("Invalid content returned").isEqualTo(content);
167168
}
168169

169-
@Test // gh-13318
170+
@Test // gh-13318
170171
void getFormBody() throws IOException {
171172
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
172173
mockRequest.setMethod("POST");
@@ -189,7 +190,7 @@ void getEmptyFormBody() throws IOException {
189190
assertThat(result).as("Invalid content returned").isEqualTo(content);
190191
}
191192

192-
@Test // gh-31327
193+
@Test // gh-31327
193194
void getFormBodyWhenQueryParamsAlsoPresent() throws IOException {
194195
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
195196
mockRequest.setMethod("POST");
@@ -203,7 +204,7 @@ void getFormBodyWhenQueryParamsAlsoPresent() throws IOException {
203204
assertThat(result).as("Invalid content returned").isEqualTo(content);
204205
}
205206

206-
@Test // gh-32471
207+
@Test // gh-32471
207208
void getFormBodyWhenNotEncodedCharactersPresent() throws IOException {
208209
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
209210
mockRequest.setMethod("POST");

spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java

+7-45
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ void resolveString() throws Exception {
150150

151151
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
152152
Object result = resolver.resolveArgument(param, null, webRequest, null);
153-
boolean condition = result instanceof String;
154-
assertThat(condition).isTrue();
155153
assertThat(result).as("Invalid result").isEqualTo(expected);
156154
}
157155

@@ -162,22 +160,18 @@ void resolveStringArray() throws Exception {
162160

163161
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
164162
Object result = resolver.resolveArgument(param, null, webRequest, null);
165-
boolean condition = result instanceof String[];
166-
assertThat(condition).isTrue();
167-
assertThat((String[]) result).as("Invalid result").isEqualTo(expected);
163+
assertThat(result).as("Invalid result").isEqualTo(expected);
168164
}
169165

170-
@Test // gh-32577
166+
@Test // gh-32577
171167
void resolveStringArrayWithEmptyArraySuffix() throws Exception {
172168
String[] expected = new String[] {"foo", "bar"};
173169
request.addParameter("name[]", expected[0]);
174170
request.addParameter("name[]", expected[1]);
175171

176172
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
177173
Object result = resolver.resolveArgument(param, null, webRequest, null);
178-
boolean condition = result instanceof String[];
179-
assertThat(condition).isTrue();
180-
assertThat((String[]) result).isEqualTo(expected);
174+
assertThat(result).isEqualTo(expected);
181175
}
182176

183177
@Test
@@ -189,8 +183,6 @@ void resolveMultipartFile() throws Exception {
189183

190184
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
191185
Object result = resolver.resolveArgument(param, null, webRequest, null);
192-
boolean condition = result instanceof MultipartFile;
193-
assertThat(condition).isTrue();
194186
assertThat(result).as("Invalid result").isEqualTo(expected);
195187
}
196188

@@ -206,9 +198,6 @@ void resolveMultipartFileList() throws Exception {
206198

207199
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
208200
Object result = resolver.resolveArgument(param, null, webRequest, null);
209-
210-
boolean condition = result instanceof List;
211-
assertThat(condition).isTrue();
212201
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
213202
}
214203

@@ -235,9 +224,7 @@ void resolveMultipartFileArray() throws Exception {
235224

236225
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
237226
Object result = resolver.resolveArgument(param, null, webRequest, null);
238-
239-
boolean condition = result instanceof MultipartFile[];
240-
assertThat(condition).isTrue();
227+
assertThat(result instanceof MultipartFile[]).isTrue();
241228
MultipartFile[] parts = (MultipartFile[]) result;
242229
assertThat(parts).hasSize(2);
243230
assertThat(expected1).isEqualTo(parts[0]);
@@ -266,9 +253,6 @@ void resolvePart() throws Exception {
266253

267254
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
268255
Object result = resolver.resolveArgument(param, null, webRequest, null);
269-
270-
boolean condition = result instanceof Part;
271-
assertThat(condition).isTrue();
272256
assertThat(result).as("Invalid result").isEqualTo(expected);
273257
}
274258

@@ -286,9 +270,6 @@ void resolvePartList() throws Exception {
286270

287271
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
288272
Object result = resolver.resolveArgument(param, null, webRequest, null);
289-
290-
boolean condition = result instanceof List;
291-
assertThat(condition).isTrue();
292273
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
293274
}
294275

@@ -319,9 +300,7 @@ void resolvePartArray() throws Exception {
319300

320301
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
321302
Object result = resolver.resolveArgument(param, null, webRequest, null);
322-
323-
boolean condition = result instanceof Part[];
324-
assertThat(condition).isTrue();
303+
assertThat(result instanceof Part[]).isTrue();
325304
Part[] parts = (Part[]) result;
326305
assertThat(parts).hasSize(2);
327306
assertThat(expected1).isEqualTo(parts[0]);
@@ -350,8 +329,6 @@ void resolveMultipartFileNotAnnot() throws Exception {
350329

351330
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
352331
Object result = resolver.resolveArgument(param, null, webRequest, null);
353-
boolean condition = result instanceof MultipartFile;
354-
assertThat(condition).isTrue();
355332
assertThat(result).as("Invalid result").isEqualTo(expected);
356333
}
357334

@@ -368,8 +345,6 @@ void resolveMultipartFileListNotannot() throws Exception {
368345
.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
369346

370347
Object result = resolver.resolveArgument(param, null, webRequest, null);
371-
boolean condition = result instanceof List;
372-
assertThat(condition).isTrue();
373348
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
374349
}
375350

@@ -424,17 +399,13 @@ void resolvePartNotAnnot() throws Exception {
424399

425400
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
426401
Object result = resolver.resolveArgument(param, null, webRequest, null);
427-
boolean condition = result instanceof Part;
428-
assertThat(condition).isTrue();
429402
assertThat(result).as("Invalid result").isEqualTo(expected);
430403
}
431404

432405
@Test
433406
void resolveDefaultValue() throws Exception {
434407
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
435408
Object result = resolver.resolveArgument(param, null, webRequest, null);
436-
boolean condition = result instanceof String;
437-
assertThat(condition).isTrue();
438409
assertThat(result).as("Invalid result").isEqualTo("bar");
439410
}
440411

@@ -452,7 +423,6 @@ public void missingRequestParamEmptyValueConvertedToNull() throws Exception {
452423

453424
WebDataBinderFactory binderFactory = mock();
454425
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
455-
456426
request.addParameter("stringNotAnnot", "");
457427

458428
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
@@ -466,7 +436,6 @@ public void missingRequestParamAfterConversionWithDefaultValue() throws Exceptio
466436

467437
WebDataBinderFactory binderFactory = mock();
468438
given(binderFactory.createBinder(webRequest, null, "booleanParam")).willReturn(binder);
469-
470439
request.addParameter("booleanParam", " ");
471440

472441
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Boolean.class);
@@ -481,22 +450,20 @@ void missingRequestParamEmptyValueNotRequired() throws Exception {
481450

482451
WebDataBinderFactory binderFactory = mock();
483452
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
484-
485453
request.addParameter("name", "");
486454

487455
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
488456
Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory);
489457
assertThat(arg).isNull();
490458
}
491459

492-
@Test // gh-29550
460+
@Test // gh-29550
493461
public void missingRequestParamEmptyValueNotRequiredWithDefaultValue() throws Exception {
494462
WebDataBinder binder = new WebRequestDataBinder(null);
495463
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
496464

497465
WebDataBinderFactory binderFactory = mock();
498466
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
499-
500467
request.addParameter("name", " ");
501468

502469
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
@@ -509,9 +476,6 @@ void resolveSimpleTypeParam() throws Exception {
509476
request.setParameter("stringNotAnnot", "plainValue");
510477
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
511478
Object result = resolver.resolveArgument(param, null, webRequest, null);
512-
513-
boolean condition = result instanceof String;
514-
assertThat(condition).isTrue();
515479
assertThat(result).isEqualTo("plainValue");
516480
}
517481

@@ -658,9 +622,7 @@ void resolveOptionalMultipartFile() throws Exception {
658622

659623
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
660624
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
661-
662-
boolean condition = result instanceof Optional;
663-
assertThat(condition).isTrue();
625+
assertThat(result instanceof Optional).isTrue();
664626
assertThat(((Optional<?>) result).get()).as("Invalid result").isEqualTo(expected);
665627
}
666628

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ private void testException(Throwable exception, String threadName, String expect
188188
TestController controller = context.getBean(TestController.class);
189189
controller.setException(exception);
190190

191-
Object actual = handle(adapter, controller, this.postExchange, Duration.ofMillis(100)
192-
, "threadWithArg", String.class).getReturnValue();
191+
Object actual = handle(adapter, controller, this.postExchange, Duration.ofMillis(1000),
192+
"threadWithArg", String.class).getReturnValue();
193193
assertThat(actual).isEqualTo(expected);
194194
}
195195

@@ -242,14 +242,14 @@ public SecondControllerAdvice anotherTestExceptionResolver() {
242242
}
243243
}
244244

245+
245246
@Controller
246247
static class TestController {
247248

248249
private Validator validator;
249250

250251
private Throwable exception;
251252

252-
253253
void setValidator(Validator validator) {
254254
this.validator = validator;
255255
}
@@ -258,7 +258,6 @@ void setException(Throwable exception) {
258258
this.exception = exception;
259259
}
260260

261-
262261
@InitBinder
263262
public void initDataBinder(WebDataBinder dataBinder) {
264263
if (this.validator != null) {
@@ -291,6 +290,7 @@ public String thread() throws Throwable {
291290
}
292291
}
293292

293+
294294
@ControllerAdvice
295295
@Order(1)
296296
static class OneControllerAdvice {
@@ -323,6 +323,7 @@ public String handleAssertionError(Error err) {
323323
}
324324
}
325325

326+
326327
@ControllerAdvice
327328
@Order(2)
328329
static class SecondControllerAdvice {

0 commit comments

Comments
 (0)