
## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Before Java 8, a container annotation was required as wrapper to use multiple instances of the same annotation.
|
|
As of Java 8, this is no longer necessary.
|
|
Instead, these annotations should be used directly without a wrapper, resulting in cleaner and more readable code.
|
|
|
|
This rule is automatically disabled when the project's `sonar.java.source` is lower than `8` as repeating annotations were introduced in Java 8.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
@SomeAnnotations({ // Noncompliant, wrapper annotations are not necessary in Java 8+
|
|
@SomeAnnotation(..a..),
|
|
@SomeAnnotation(..b..),
|
|
@SomeAnnotation(..c..),
|
|
})
|
|
public class SomeClass {
|
|
...
|
|
}
|
|
----
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
@SomeAnnotation(..a..)
|
|
@SomeAnnotation(..b..)
|
|
@SomeAnnotation(..c..)
|
|
public class SomeClass {
|
|
...
|
|
}
|
|
----
|
|
|
|
== References
|
|
* https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html[Repeating Annotations - The Java™ Tutorials]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove the XXX wrapper from this annotation group. [(sonar.java.source not set. Assuming 8 or greater.)]
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|