Skip to content

Commit f8c5f36

Browse files
committed
GH-1341 - Avoid potential NullPointerException in annotation lookup for JavaPackage.
We now explicitly filter null values in the annotation lookup that could stem from the initial filtering based on the sole presence of the annotation and the subsequent step trying to load that annotation.
1 parent 27800de commit f8c5f36

File tree

1 file changed

+4
-1
lines changed
  • spring-modulith-core/src/main/java/org/springframework/modulith/core

1 file changed

+4
-1
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/JavaPackage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collection;
2525
import java.util.Comparator;
2626
import java.util.Iterator;
27+
import java.util.List;
2728
import java.util.Map.Entry;
2829
import java.util.Objects;
2930
import java.util.Optional;
@@ -36,6 +37,7 @@
3637
import java.util.stream.Stream;
3738
import java.util.stream.StreamSupport;
3839

40+
import org.jspecify.annotations.NonNull;
3941
import org.springframework.core.annotation.AnnotatedElementUtils;
4042
import org.springframework.modulith.PackageInfo;
4143
import org.springframework.util.Assert;
@@ -407,11 +409,12 @@ public <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType
407409

408410
var isPackageInfo = have(simpleName(PACKAGE_INFO_NAME)).or(are(metaAnnotatedWith(PackageInfo.class)));
409411

410-
var annotatedTypes = toSingle().classes
412+
List<@NonNull A> annotatedTypes = toSingle().classes
411413
.that(isPackageInfo.and(are(metaAnnotatedWith(annotationType))))
412414
.stream()
413415
.map(JavaClass::reflect)
414416
.map(it -> AnnotatedElementUtils.findMergedAnnotation(it, annotationType))
417+
.filter(it -> it != null)
415418
.toList();
416419

417420
if (annotatedTypes.size() > 1) {

0 commit comments

Comments
 (0)