Skip to content

Commit 1195b3a

Browse files
committed
Polishing
1 parent 5672166 commit 1195b3a

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.aop.Advisor;
2222
import org.springframework.aop.PointcutAdvisor;
2323
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
24+
import org.springframework.lang.Nullable;
2425
import org.springframework.util.StringUtils;
2526

2627
/**
@@ -74,7 +75,7 @@ private static boolean isAspectJAdvice(Advisor advisor) {
7475
((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut));
7576
}
7677

77-
static boolean isVariableName(String name) {
78+
static boolean isVariableName(@Nullable String name) {
7879
if (!StringUtils.hasLength(name)) {
7980
return false;
8081
}
@@ -88,4 +89,5 @@ static boolean isVariableName(String name) {
8889
}
8990
return true;
9091
}
92+
9193
}

spring-web/src/main/java/org/springframework/http/converter/json/KotlinSerializationJsonHttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable Med
100100
}
101101

102102
@Override
103-
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) {
103+
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
104104
try {
105-
serializer(GenericTypeResolver.resolveType(type, clazz));
105+
serializer(type != null ? GenericTypeResolver.resolveType(type, clazz) : clazz);
106106
return canWrite(mediaType);
107107
}
108108
catch (Exception ex) {

spring-web/src/test/kotlin/org/springframework/http/codec/json/KotlinSerializationJsonDecoderTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class KotlinSerializationJsonDecoderTests : AbstractDecoderTests<KotlinSerializa
9797
}
9898
}
9999

100+
100101
@Serializable
101102
data class Pojo(val foo: String, val bar: String)
102103

103-
}
104+
}

spring-web/src/test/kotlin/org/springframework/http/codec/json/KotlinSerializationJsonEncoderTests.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa
9393
Assertions.assertThat(encoder.canEncode(sseType, MediaType.APPLICATION_JSON)).isFalse()
9494
}
9595

96+
9697
@Serializable
9798
data class Pojo(val foo: String, val bar: String)
9899

99-
}
100+
}

spring-web/src/test/kotlin/org/springframework/http/converter/json/KotlinSerializationJsonHttpMessageConverterTests.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ class KotlinSerializationJsonHttpMessageConverterTests {
6969
assertThat(converter.canWrite(List::class.java, MediaType.APPLICATION_JSON)).isTrue()
7070
assertThat(converter.canWrite(Set::class.java, MediaType.APPLICATION_JSON)).isTrue()
7171

72-
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue()
73-
assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), null, MediaType.APPLICATION_JSON)).isTrue()
74-
assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue()
75-
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_PDF)).isFalse()
72+
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
73+
assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
74+
assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
75+
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_PDF)).isFalse()
7676
}
7777

7878
@Test
@@ -297,6 +297,7 @@ class KotlinSerializationJsonHttpMessageConverterTests {
297297
assertThat(result).isEqualTo("\"H\u00e9llo W\u00f6rld\"")
298298
}
299299

300+
300301
@Serializable
301302
@Suppress("ArrayInDataClass")
302303
data class SerializableBean(
@@ -317,4 +318,5 @@ class KotlinSerializationJsonHttpMessageConverterTests {
317318
val superType = base::class.java.genericSuperclass!!
318319
return (superType as ParameterizedType).actualTypeArguments.first()!!
319320
}
321+
320322
}

spring-websocket/src/main/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Collection;
2121
import java.util.Collections;
22-
import java.util.HashSet;
22+
import java.util.LinkedHashSet;
2323
import java.util.List;
2424
import java.util.Map;
2525

@@ -31,6 +31,7 @@
3131
import org.springframework.http.server.ServerHttpResponse;
3232
import org.springframework.lang.Nullable;
3333
import org.springframework.util.Assert;
34+
import org.springframework.util.CollectionUtils;
3435
import org.springframework.web.cors.CorsConfiguration;
3536
import org.springframework.web.socket.WebSocketHandler;
3637
import org.springframework.web.socket.server.HandshakeInterceptor;
@@ -84,9 +85,9 @@ public void setAllowedOrigins(Collection<String> allowedOrigins) {
8485
* @since 4.1.5
8586
*/
8687
public Collection<String> getAllowedOrigins() {
87-
return (this.corsConfiguration.getAllowedOrigins() != null ?
88-
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOrigins())) :
89-
Collections.emptyList());
88+
List<String> allowedOrigins = this.corsConfiguration.getAllowedOrigins();
89+
return (CollectionUtils.isEmpty(allowedOrigins) ? Collections.emptySet() :
90+
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOrigins)));
9091
}
9192

9293
/**
@@ -104,14 +105,13 @@ public void setAllowedOriginPatterns(Collection<String> allowedOriginPatterns) {
104105

105106
/**
106107
* Return the allowed {@code Origin} pattern header values.
107-
*
108108
* @since 5.3.2
109109
* @see CorsConfiguration#getAllowedOriginPatterns()
110110
*/
111111
public Collection<String> getAllowedOriginPatterns() {
112-
return (this.corsConfiguration.getAllowedOriginPatterns() != null ?
113-
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOriginPatterns())) :
114-
Collections.emptyList());
112+
List<String> allowedOriginPatterns = this.corsConfiguration.getAllowedOriginPatterns();
113+
return (CollectionUtils.isEmpty(allowedOriginPatterns) ? Collections.emptySet() :
114+
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOriginPatterns)));
115115
}
116116

117117

0 commit comments

Comments
 (0)