Polishing

This commit is contained in:
Juergen Hoeller 2020-12-08 10:39:56 +01:00
parent 56721669d1
commit 1195b3a0b0
6 changed files with 24 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.util.List;
import org.springframework.aop.Advisor; import org.springframework.aop.Advisor;
import org.springframework.aop.PointcutAdvisor; import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -74,7 +75,7 @@ public abstract class AspectJProxyUtils {
((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut)); ((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut));
} }
static boolean isVariableName(String name) { static boolean isVariableName(@Nullable String name) {
if (!StringUtils.hasLength(name)) { if (!StringUtils.hasLength(name)) {
return false; return false;
} }
@ -88,4 +89,5 @@ public abstract class AspectJProxyUtils {
} }
return true; return true;
} }
} }

View File

@ -100,9 +100,9 @@ public class KotlinSerializationJsonHttpMessageConverter extends AbstractGeneric
} }
@Override @Override
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) { public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
try { try {
serializer(GenericTypeResolver.resolveType(type, clazz)); serializer(type != null ? GenericTypeResolver.resolveType(type, clazz) : clazz);
return canWrite(mediaType); return canWrite(mediaType);
} }
catch (Exception ex) { catch (Exception ex) {

View File

@ -97,7 +97,8 @@ class KotlinSerializationJsonDecoderTests : AbstractDecoderTests<KotlinSerializa
} }
} }
@Serializable @Serializable
data class Pojo(val foo: String, val bar: String) data class Pojo(val foo: String, val bar: String)
} }

View File

@ -93,7 +93,8 @@ class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa
Assertions.assertThat(encoder.canEncode(sseType, MediaType.APPLICATION_JSON)).isFalse() Assertions.assertThat(encoder.canEncode(sseType, MediaType.APPLICATION_JSON)).isFalse()
} }
@Serializable @Serializable
data class Pojo(val foo: String, val bar: String) data class Pojo(val foo: String, val bar: String)
} }

View File

@ -69,10 +69,10 @@ class KotlinSerializationJsonHttpMessageConverterTests {
assertThat(converter.canWrite(List::class.java, MediaType.APPLICATION_JSON)).isTrue() assertThat(converter.canWrite(List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(Set::class.java, MediaType.APPLICATION_JSON)).isTrue() assertThat(converter.canWrite(Set::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue() assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), null, MediaType.APPLICATION_JSON)).isTrue() assertThat(converter.canWrite(typeTokenOf<List<SerializableBean>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), null, MediaType.APPLICATION_JSON)).isTrue() assertThat(converter.canWrite(typeTokenOf<ArrayList<Int>>(), List::class.java, MediaType.APPLICATION_JSON)).isTrue()
assertThat(converter.canWrite(typeTokenOf<List<Int>>(), null, MediaType.APPLICATION_PDF)).isFalse() assertThat(converter.canWrite(typeTokenOf<List<Int>>(), List::class.java, MediaType.APPLICATION_PDF)).isFalse()
} }
@Test @Test
@ -297,6 +297,7 @@ class KotlinSerializationJsonHttpMessageConverterTests {
assertThat(result).isEqualTo("\"H\u00e9llo W\u00f6rld\"") assertThat(result).isEqualTo("\"H\u00e9llo W\u00f6rld\"")
} }
@Serializable @Serializable
@Suppress("ArrayInDataClass") @Suppress("ArrayInDataClass")
data class SerializableBean( data class SerializableBean(
@ -317,4 +318,5 @@ class KotlinSerializationJsonHttpMessageConverterTests {
val superType = base::class.java.genericSuperclass!! val superType = base::class.java.genericSuperclass!!
return (superType as ParameterizedType).actualTypeArguments.first()!! return (superType as ParameterizedType).actualTypeArguments.first()!!
} }
} }

View File

@ -19,7 +19,7 @@ package org.springframework.web.socket.server.support;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -31,6 +31,7 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServerHttpResponse;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeInterceptor; import org.springframework.web.socket.server.HandshakeInterceptor;
@ -84,9 +85,9 @@ public class OriginHandshakeInterceptor implements HandshakeInterceptor {
* @since 4.1.5 * @since 4.1.5
*/ */
public Collection<String> getAllowedOrigins() { public Collection<String> getAllowedOrigins() {
return (this.corsConfiguration.getAllowedOrigins() != null ? List<String> allowedOrigins = this.corsConfiguration.getAllowedOrigins();
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOrigins())) : return (CollectionUtils.isEmpty(allowedOrigins) ? Collections.emptySet() :
Collections.emptyList()); Collections.unmodifiableSet(new LinkedHashSet<>(allowedOrigins)));
} }
/** /**
@ -104,14 +105,13 @@ public class OriginHandshakeInterceptor implements HandshakeInterceptor {
/** /**
* Return the allowed {@code Origin} pattern header values. * Return the allowed {@code Origin} pattern header values.
*
* @since 5.3.2 * @since 5.3.2
* @see CorsConfiguration#getAllowedOriginPatterns() * @see CorsConfiguration#getAllowedOriginPatterns()
*/ */
public Collection<String> getAllowedOriginPatterns() { public Collection<String> getAllowedOriginPatterns() {
return (this.corsConfiguration.getAllowedOriginPatterns() != null ? List<String> allowedOriginPatterns = this.corsConfiguration.getAllowedOriginPatterns();
Collections.unmodifiableSet(new HashSet<>(this.corsConfiguration.getAllowedOriginPatterns())) : return (CollectionUtils.isEmpty(allowedOriginPatterns) ? Collections.emptySet() :
Collections.emptyList()); Collections.unmodifiableSet(new LinkedHashSet<>(allowedOriginPatterns)));
} }