Skip to content

Commit 36019b7

Browse files
committed
Use ListIterator to improve support for non-random-access lists
1 parent ae9fe7f commit 36019b7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Field;
2020
import java.lang.reflect.Method;
2121
import java.util.List;
22+
import java.util.ListIterator;
2223
import java.util.Optional;
2324
import java.util.function.Predicate;
2425

@@ -220,8 +221,9 @@ public static <A extends Annotation> Optional<A> findAnnotation(Class<?> clazz,
220221

221222
Optional<A> annotation = findAnnotation(clazz, annotationType);
222223
if (!annotation.isPresent()) {
223-
for (int i = enclosingInstanceTypes.size() - 1; i >= 0; i--) {
224-
annotation = findAnnotation(enclosingInstanceTypes.get(i), annotationType);
224+
ListIterator<Class<?>> iterator = enclosingInstanceTypes.listIterator(enclosingInstanceTypes.size());
225+
while (iterator.hasPrevious()) {
226+
annotation = findAnnotation(iterator.previous(), annotationType);
225227
if (annotation.isPresent()) {
226228
break;
227229
}

0 commit comments

Comments
 (0)