Value Annotation Without Expression
ID |
java.spring_value_without_expression |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
best-practice, reliability, spring |
Description
Reports a field annotated @Value whose string literal is neither a property placeholder nor a SpEL expression.
Rationale
@Value injects a property placeholder or evaluates a SpEL expression — both are written with a distinct opening marker before the braces. Without one of those markers, @Value injects the literal text of the string itself, unchanged. The field ends up holding the annotation’s argument verbatim rather than a value resolved from the Spring context, and nothing reports the mismatch because the annotation is syntactically valid either way. This usually means the marker was left out by mistake, or the field never needed @Value in the first place.
Only fields are reported. @Value on a method or a method parameter is a legitimate use even without a placeholder or expression, because there the annotation’s effect is that the method gets called — that carve-out is deliberate and matches how the annotation actually works there.
// Bad - injects the literal text "catalog.name", not the configured property
@Value("catalog.name")
private String catalogName;