From 0aa3205e3865c34ee98a5d14eeca03abf8f871d4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 26 Oct 2020 22:19:26 +0100 Subject: [PATCH] Fix nullability warnings --- .../AbstractEncoderMethodReturnValueHandler.java | 9 +++++---- .../test/context/TestContextAnnotationUtils.java | 15 ++++++++++----- .../context/support/TestPropertySourceUtils.java | 9 ++++----- .../interceptor/TransactionAspectSupport.java | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java index 0981f408c4..38536d9a8d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java @@ -16,6 +16,7 @@ package org.springframework.messaging.handler.invocation.reactive; +import java.lang.reflect.Method; import java.util.Collections; import java.util.List; import java.util.Map; @@ -120,7 +121,6 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler handleEncodedContent(Flux.from(publisher), returnType, message)); } - @SuppressWarnings("unchecked") private Flux encodeContent( @Nullable Object content, MethodParameter returnType, DataBufferFactory bufferFactory, @Nullable MimeType mimeType, Map hints) { @@ -132,9 +132,10 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler ResolvableType elementType; if (adapter != null) { publisher = adapter.toPublisher(content); - boolean isUnwrapped = KotlinDetector.isSuspendingFunction(returnType.getMethod()) && - !COROUTINES_FLOW_CLASS_NAME.equals(returnValueType.toClass().getName()); - ResolvableType genericType = isUnwrapped ? returnValueType : returnValueType.getGeneric(); + Method method = returnType.getMethod(); + boolean isUnwrapped = (method != null && KotlinDetector.isSuspendingFunction(method) && + !COROUTINES_FLOW_CLASS_NAME.equals(returnValueType.toClass().getName())); + ResolvableType genericType = (isUnwrapped ? returnValueType : returnValueType.getGeneric()); elementType = getElementType(adapter, genericType); } else { diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java index 23e56c1c1c..949ed8afbc 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java @@ -75,8 +75,10 @@ public abstract class TestContextAnnotationUtils { private static final ConcurrentLruCache, EnclosingConfiguration> cachedEnclosingConfigurationModes = new ConcurrentLruCache<>(32, TestContextAnnotationUtils::lookUpEnclosingConfiguration); + @Nullable private static volatile EnclosingConfiguration defaultEnclosingConfigurationMode; + /** * Find the first annotation of the specified {@code annotationType} within * the annotation hierarchy above the supplied class, merge that @@ -411,13 +413,15 @@ public abstract class TestContextAnnotationUtils { } private static EnclosingConfiguration getDefaultEnclosingConfigurationMode() { - if (defaultEnclosingConfigurationMode == null) { + EnclosingConfiguration defaultConfigurationMode = defaultEnclosingConfigurationMode; + if (defaultConfigurationMode == null) { String value = SpringProperties.getProperty(NestedTestConfiguration.ENCLOSING_CONFIGURATION_PROPERTY_NAME); EnclosingConfiguration enclosingConfigurationMode = EnclosingConfiguration.from(value); - defaultEnclosingConfigurationMode = + defaultConfigurationMode = (enclosingConfigurationMode != null ? enclosingConfigurationMode : EnclosingConfiguration.INHERIT); + defaultEnclosingConfigurationMode = defaultConfigurationMode; } - return defaultEnclosingConfigurationMode; + return defaultConfigurationMode; } private static void assertNonEmptyAnnotationTypeArray(Class[] annotationTypes, String message) { @@ -503,9 +507,10 @@ public abstract class TestContextAnnotationUtils { this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; - this.annotationAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes( + AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( rootDeclaringClass, annotation.annotationType().getName(), false, false); - Assert.state(this.annotationAttributes != null, "No annotation attributes"); + Assert.state(attributes != null, "No annotation attributes"); + this.annotationAttributes = attributes; } public Class getRootDeclaringClass() { diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 5d5a47f66f..5ed7f4aafb 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -126,16 +126,15 @@ public abstract class TestPropertySourceUtils { } private static boolean duplicationDetected(TestPropertySourceAttributes currentAttributes, - TestPropertySourceAttributes previousAttributes) { + @Nullable TestPropertySourceAttributes previousAttributes) { boolean duplicationDetected = (currentAttributes.equals(previousAttributes) && !currentAttributes.isEmpty()); if (duplicationDetected && logger.isDebugEnabled()) { - logger.debug(String.format("Ignoring duplicate %s declaration on %s, " - + "since it is also declared on %s.", currentAttributes, - previousAttributes.getDeclaringClass().getName(), - currentAttributes.getDeclaringClass().getName())); + logger.debug(String.format("Ignoring duplicate %s declaration on %s since it is also declared on %s", + currentAttributes, currentAttributes.getDeclaringClass().getName(), + previousAttributes.getDeclaringClass().getName())); } return duplicationDetected; diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java index 263e99a008..9ae7a02927 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java @@ -851,6 +851,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init } @SuppressWarnings("unchecked") + @Nullable private static Object awaitSingleOrNull(Publisher publisher, Object continuation) { return AwaitKt.awaitSingleOrNull(publisher, (Continuation) continuation); }