An injection or validation annotation sits on a static field, where it is ignored
What it finds
Dependency injection and bean validation work on instances: Spring and Jakarta injection do not fill a static field marked @Autowired, @Inject, @Value or @Resource, so it stays null, and Bean Validation ignores constraints such as @NotNull on static fields, as the specification says.
Reported is one of these annotations on a static field, and @Autowired or @Inject on a static method.
From the rule's source, static_member_annotation.rs.
import javax.validation.constraints.NotNull;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value; class Service { @Autowiredtx0 reports: @Autowired is ignored on a static member private static Object repository; @Value("${name}")tx0 reports: @Value is ignored static String name; @NotNulltx0 reports: @NotNull is ignored static String code; @Autowired private Object other;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:static-member-annotation" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:static-member-annotation] reason="..."tx0 explain tx0/java:static-member-annotation shows the same in the terminal. Found a false positive? Report it.