From bd2640a9d67ef1f8cffb8a8ed0c4a6539d5b4712 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 9 Nov 2020 21:33:32 +0100 Subject: [PATCH] Strict nullability for field assignment --- .../test/context/TestContextAnnotationUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 62300498b6e..1c01b0a07ea 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 @@ -492,10 +492,11 @@ public abstract class TestContextAnnotationUtils { Assert.notNull(annotation, "Annotation must not be null"); this.rootDeclaringClass = rootDeclaringClass; this.declaringClass = declaringClass; - this.annotation = (T) AnnotatedElementUtils.findMergedAnnotation( + T mergedAnnotation = (T) AnnotatedElementUtils.findMergedAnnotation( rootDeclaringClass, annotation.annotationType()); - Assert.state(this.annotation != null, + Assert.state(mergedAnnotation != null, () -> "Failed to find merged annotation for " + annotation); + this.annotation = mergedAnnotation; } public Class getRootDeclaringClass() {