Skip to content

Commit 34e6627

Browse files
committed
Fix nullability annotations in ReflectionUtils and AnnotationSupport
1 parent 6183a63 commit 34e6627

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

junit-platform-commons/src/main/java/org/junit/platform/commons/support/AnnotationSupport.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ public static List<Field> findAnnotatedFields(Class<?> clazz, Class<? extends An
443443
* @see ReflectionSupport#tryToReadFieldValue(Field, Object)
444444
*/
445445
@API(status = MAINTAINED, since = "1.4")
446-
public static List<Object> findAnnotatedFieldValues(Object instance, Class<? extends Annotation> annotationType) {
446+
public static List<@Nullable Object> findAnnotatedFieldValues(Object instance,
447+
Class<? extends Annotation> annotationType) {
447448
Preconditions.notNull(instance, "instance must not be null");
448449

449450
List<Field> fields = findAnnotatedFields(instance.getClass(), annotationType, ModifierSupport::isNotStatic,
@@ -475,7 +476,8 @@ public static List<Object> findAnnotatedFieldValues(Object instance, Class<? ext
475476
* @see ReflectionSupport#tryToReadFieldValue(Field, Object)
476477
*/
477478
@API(status = MAINTAINED, since = "1.4")
478-
public static List<Object> findAnnotatedFieldValues(Class<?> clazz, Class<? extends Annotation> annotationType) {
479+
public static List<@Nullable Object> findAnnotatedFieldValues(Class<?> clazz,
480+
Class<? extends Annotation> annotationType) {
479481

480482
List<Field> fields = findAnnotatedFields(clazz, annotationType, ModifierSupport::isStatic,
481483
HierarchyTraversalMode.TOP_DOWN);
@@ -510,8 +512,8 @@ public static List<Object> findAnnotatedFieldValues(Class<?> clazz, Class<? exte
510512
*/
511513
@SuppressWarnings("unchecked")
512514
@API(status = MAINTAINED, since = "1.4")
513-
public static <T> List<T> findAnnotatedFieldValues(Object instance, Class<? extends Annotation> annotationType,
514-
Class<T> fieldType) {
515+
public static <T extends @Nullable Object> List<T> findAnnotatedFieldValues(Object instance,
516+
Class<? extends Annotation> annotationType, Class<T> fieldType) {
515517

516518
Preconditions.notNull(instance, "instance must not be null");
517519
Preconditions.notNull(fieldType, "fieldType must not be null");
@@ -552,8 +554,8 @@ public static <T> List<T> findAnnotatedFieldValues(Object instance, Class<? exte
552554
*/
553555
@SuppressWarnings("unchecked")
554556
@API(status = MAINTAINED, since = "1.4")
555-
public static <T> List<T> findAnnotatedFieldValues(Class<?> clazz, Class<? extends Annotation> annotationType,
556-
Class<T> fieldType) {
557+
public static <T extends @Nullable Object> List<T> findAnnotatedFieldValues(Class<?> clazz,
558+
Class<? extends Annotation> annotationType, Class<T> fieldType) {
557559

558560
Preconditions.notNull(fieldType, "fieldType must not be null");
559561

junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public static <T> T newInstance(Constructor<T> constructor, @Nullable Object...
626626
* @see #tryToReadFieldValue(Field, Object)
627627
*/
628628
@API(status = INTERNAL, since = "1.4")
629-
public static <T> Try<Object> tryToReadFieldValue(Class<T> clazz, String fieldName, T instance) {
629+
public static <T> Try<Object> tryToReadFieldValue(Class<T> clazz, String fieldName, @Nullable T instance) {
630630
Preconditions.notNull(clazz, "Class must not be null");
631631
Preconditions.notBlank(fieldName, "Field name must not be null or blank");
632632

@@ -677,7 +677,7 @@ public static <T> Try<Object> tryToReadFieldValue(Class<T> clazz, String fieldNa
677677
* @return an immutable list of the values of the specified fields; never
678678
* {@code null} but may be empty or contain {@code null} entries
679679
*/
680-
public static List<Object> readFieldValues(List<Field> fields, @Nullable Object instance) {
680+
public static List<@Nullable Object> readFieldValues(List<Field> fields, @Nullable Object instance) {
681681
return readFieldValues(fields, instance, field -> true);
682682
}
683683

@@ -694,7 +694,7 @@ public static List<Object> readFieldValues(List<Field> fields, @Nullable Object
694694
* @return an immutable list of the values of the specified fields; never
695695
* {@code null} but may be empty or contain {@code null} entries
696696
*/
697-
public static List<Object> readFieldValues(List<Field> fields, @Nullable Object instance,
697+
public static List<@Nullable Object> readFieldValues(List<Field> fields, @Nullable Object instance,
698698
Predicate<Field> predicate) {
699699
Preconditions.notNull(fields, "fields list must not be null");
700700
Preconditions.notNull(predicate, "Predicate must not be null");

0 commit comments

Comments
 (0)