Skip to content

Commit f07e3ff

Browse files
YongGoosesbrannen
andauthored
Document that AnnotationSupport.isAnnotated() does not find repeatable annotations (#4243)
Resolves #4058. --------- Co-authored-by: Sam Brannen <[email protected]>
1 parent 1a03531 commit f07e3ff

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

documentation/src/docs/asciidoc/user-guide/extensions.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,9 @@ and fields in a class or interface. Some of these methods search on implemented
871871
interfaces and within class hierarchies to find annotations. Consult the Javadoc for
872872
`{AnnotationSupport}` for further details.
873873

874+
NOTE: The `isAnnotated()` methods do not find repeatable annotations. To check for repeatable annotations,
875+
use one of the `findRepeatableAnnotations()` methods and verify that the returned list is not empty.
876+
874877
NOTE: See also: <<extensions-supported-utilities-search-semantics>>
875878

876879
[[extensions-supported-utilities-classes]]

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/AnnotatedElementContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public interface AnnotatedElementContext {
5555
* <em>present</em> or <em>meta-present</em> on the {@link AnnotatedElement} for
5656
* this context.
5757
*
58+
* <p><strong>Note:</strong> This method does not find repeatable annotations.
59+
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(Class)}
60+
* and verify that the returned list is not empty.
61+
*
5862
* <h4>WARNING</h4>
5963
* <p>Favor the use of this method over directly invoking
6064
* {@link AnnotatedElement#isAnnotationPresent(Class)} due to a bug in {@code javac}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ private AnnotationSupport() {
5454
* <em>present</em> or <em>meta-present</em> on the supplied optional
5555
* {@code element}.
5656
*
57+
* <p><strong>Note:</strong> This method does not find repeatable annotations.
58+
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(Optional, Class)}
59+
* and verify that the returned list is not empty.
60+
*
5761
* @param element an {@link Optional} containing the element on which to
5862
* search for the annotation; may be {@code null} or <em>empty</em>
5963
* @param annotationType the annotation type to search for; never {@code null}
6064
* @return {@code true} if the annotation is present or meta-present
6165
* @since 1.3
6266
* @see #isAnnotated(AnnotatedElement, Class)
6367
* @see #findAnnotation(Optional, Class)
68+
* @see #findRepeatableAnnotations(Optional, Class)
6469
*/
6570
@API(status = MAINTAINED, since = "1.3")
6671
public static boolean isAnnotated(Optional<? extends AnnotatedElement> element,
@@ -74,12 +79,17 @@ public static boolean isAnnotated(Optional<? extends AnnotatedElement> element,
7479
* <em>present</em> or <em>meta-present</em> on the supplied
7580
* {@code element}.
7681
*
82+
* <p><strong>Note:</strong> This method does not find repeatable annotations.
83+
* To check for repeatable annotations, use {@link #findRepeatableAnnotations(AnnotatedElement, Class)}
84+
* and verify that the returned list is not empty.
85+
*
7786
* @param element the element on which to search for the annotation; may be
7887
* {@code null}
7988
* @param annotationType the annotation type to search for; never {@code null}
8089
* @return {@code true} if the annotation is present or meta-present
8190
* @see #isAnnotated(Optional, Class)
8291
* @see #findAnnotation(AnnotatedElement, Class)
92+
* @see #findRepeatableAnnotations(AnnotatedElement, Class)
8393
*/
8494
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType) {
8595
return AnnotationUtils.isAnnotated(element, annotationType);

0 commit comments

Comments
 (0)