Skip to content

Commit 7f36594

Browse files
committed
Nullability refinements and related polishing
1 parent 1b63c31 commit 7f36594

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ public static boolean isKotlinType(Class<?> clazz) {
7777

7878
/**
7979
* Return {@code true} if the method is a suspending function.
80-
*
8180
* @author Sebastien Deleuze
8281
* @since 5.3
8382
*/
8483
public static boolean isSuspendingFunction(Method method) {
8584
if (KotlinDetector.isKotlinType(method.getDeclaringClass())) {
8685
Class<?>[] types = method.getParameterTypes();
87-
if ((types.length > 0) && "kotlin.coroutines.Continuation".equals(types[types.length - 1].getName())) {
86+
if (types.length > 0 && "kotlin.coroutines.Continuation".equals(types[types.length - 1].getName())) {
8887
return true;
8988
}
9089
}

spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.commons.logging.LogFactory;
2828

2929
import org.springframework.core.annotation.AnnotationUtils;
30+
import org.springframework.lang.Nullable;
3031
import org.springframework.test.context.ContextConfiguration;
3132
import org.springframework.test.context.ContextConfigurationAttributes;
3233
import org.springframework.test.context.ContextHierarchy;
@@ -249,11 +250,11 @@ static List<ContextConfigurationAttributes> resolveContextConfigurationAttribute
249250
}
250251

251252
private static void resolveContextConfigurationAttributes(List<ContextConfigurationAttributes> attributesList,
252-
AnnotationDescriptor<ContextConfiguration> descriptor) {
253+
@Nullable AnnotationDescriptor<ContextConfiguration> descriptor) {
253254

254255
if (descriptor != null) {
255256
convertContextConfigToConfigAttributesAndAddToList(descriptor.synthesizeAnnotation(),
256-
descriptor.getRootDeclaringClass(), attributesList);
257+
descriptor.getRootDeclaringClass(), attributesList);
257258
resolveContextConfigurationAttributes(attributesList, descriptor.next());
258259
}
259260
}

spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
163163
return findTransactionAttributeInEnclosingClassHierarchy(clazz);
164164
}
165165

166+
@Nullable
166167
private TransactionAttribute findTransactionAttributeInEnclosingClassHierarchy(Class<?> clazz) {
167168
if (MetaAnnotationUtils.searchEnclosingClass(clazz)) {
168169
return findTransactionAttribute(clazz.getEnclosingClass());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.test.context.web;
1818

19+
import org.springframework.lang.Nullable;
1920
import org.springframework.test.context.ContextLoader;
2021
import org.springframework.test.context.MergedContextConfiguration;
2122
import org.springframework.test.context.TestContextBootstrapper;
@@ -70,6 +71,7 @@ protected MergedContextConfiguration processMergedContextConfiguration(MergedCon
7071
}
7172
}
7273

74+
@Nullable
7375
private static WebAppConfiguration getWebAppConfiguration(Class<?> testClass) {
7476
return MetaAnnotationUtils.findMergedAnnotation(testClass, WebAppConfiguration.class);
7577
}

spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonDecoder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.core.codec.StringDecoder;
3232
import org.springframework.core.io.buffer.DataBuffer;
3333
import org.springframework.http.MediaType;
34+
import org.springframework.lang.Nullable;
3435
import org.springframework.util.ConcurrentReferenceHashMap;
3536
import org.springframework.util.MimeType;
3637

@@ -58,6 +59,7 @@ public class KotlinSerializationJsonDecoder extends AbstractDecoder<Object> {
5859
// String decoding needed for now, see https://github.com/Kotlin/kotlinx.serialization/issues/204 for more details
5960
private final StringDecoder stringDecoder = StringDecoder.allMimeTypes(StringDecoder.DEFAULT_DELIMITERS, false);
6061

62+
6163
public KotlinSerializationJsonDecoder() {
6264
this(Json.Default);
6365
}
@@ -67,18 +69,23 @@ public KotlinSerializationJsonDecoder(Json json) {
6769
this.json = json;
6870
}
6971

72+
7073
@Override
71-
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
72-
return super.canDecode(elementType, mimeType) && (!CharSequence.class.isAssignableFrom(elementType.toClass()));
74+
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
75+
return (super.canDecode(elementType, mimeType) && !CharSequence.class.isAssignableFrom(elementType.toClass()));
7376
}
7477

7578
@Override
76-
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
79+
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
80+
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
81+
7782
return Flux.error(new UnsupportedOperationException());
7883
}
7984

8085
@Override
81-
public Mono<Object> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
86+
public Mono<Object> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
87+
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
88+
8289
return this.stringDecoder
8390
.decodeToMono(inputStream, elementType, mimeType, hints)
8491
.map(jsonText -> this.json.decodeFromString(serializer(elementType.getType()), jsonText));
@@ -100,4 +107,5 @@ private KSerializer<Object> serializer(Type type) {
100107
}
101108
return serializer;
102109
}
110+
103111
}

spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonEncoder.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.core.io.buffer.DataBufferFactory;
3535
import org.springframework.http.MediaType;
3636
import org.springframework.http.codec.ServerSentEvent;
37+
import org.springframework.lang.Nullable;
3738
import org.springframework.util.ConcurrentReferenceHashMap;
3839
import org.springframework.util.MimeType;
3940

@@ -57,6 +58,7 @@ public class KotlinSerializationJsonEncoder extends AbstractEncoder<Object> {
5758
// CharSequence encoding needed for now, see https://github.com/Kotlin/kotlinx.serialization/issues/204 for more details
5859
private final CharSequenceEncoder charSequenceEncoder = CharSequenceEncoder.allMimeTypes();
5960

61+
6062
public KotlinSerializationJsonEncoder() {
6163
this(Json.Default);
6264
}
@@ -66,15 +68,17 @@ public KotlinSerializationJsonEncoder(Json json) {
6668
this.json = json;
6769
}
6870

71+
6972
@Override
70-
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
71-
return super.canEncode(elementType, mimeType)
72-
&& (!String.class.isAssignableFrom(elementType.toClass()))
73-
&& (!ServerSentEvent.class.isAssignableFrom(elementType.toClass()));
73+
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
74+
return (super.canEncode(elementType, mimeType) && !String.class.isAssignableFrom(elementType.toClass()) &&
75+
!ServerSentEvent.class.isAssignableFrom(elementType.toClass()));
7476
}
7577

7678
@Override
77-
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
79+
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory,
80+
ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
81+
7882
if (inputStream instanceof Mono) {
7983
return Mono.from(inputStream)
8084
.map(value -> encodeValue(value, bufferFactory, elementType, mimeType, hints))
@@ -90,7 +94,9 @@ public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory buffe
9094
}
9195

9296
@Override
93-
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints) {
97+
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
98+
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
99+
94100
String json = this.json.encodeToString(serializer(valueType.getType()), value);
95101
return this.charSequenceEncoder.encodeValue(json, bufferFactory, valueType, mimeType, null);
96102
}
@@ -111,4 +117,5 @@ private KSerializer<Object> serializer(Type type) {
111117
}
112118
return serializer;
113119
}
120+
114121
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ContinuationHandlerMethodArgumentResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.web.servlet.mvc.method.annotation;
1818

1919
import org.springframework.core.MethodParameter;
20+
import org.springframework.lang.Nullable;
2021
import org.springframework.web.bind.support.WebDataBinderFactory;
2122
import org.springframework.web.context.request.NativeWebRequest;
2223
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
@@ -36,7 +37,10 @@ public boolean supportsParameter(MethodParameter parameter) {
3637
}
3738

3839
@Override
39-
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
40+
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
41+
NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
42+
4043
return null;
4144
}
45+
4246
}

0 commit comments

Comments
 (0)