Skip to content

Commit

Permalink
update after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-serandour committed Jan 24, 2025
1 parent cf3abe4 commit e265d1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rules/S7178/java/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "HIGH",
"MAINTAINABILITY": "LOW",
"RELIABILITY": "HIGH",
"SECURITY": "LOW"
},
Expand Down
10 changes: 5 additions & 5 deletions rules/S7178/java/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Spring dependency injection framework does not support injecting data into static fields. When @Value, @Inject, or @Autowired are applied to static fields, they are ignored.

What is the potential impact?
=== What is the potential impact?

* Null Values: Uninitialized static fields annotated with @Value, @Inject, or @Autowired will not be initialized by Spring, potentially causing NullPointerException at runtime.
* Confusing Code: The presence of injection annotations on static fields can mislead developers into believing that the fields will be populated by Spring.
* *Null Values*: Uninitialized static fields annotated with @Value, @Inject, or @Autowired will not be initialized by Spring, potentially causing NullPointerException at runtime.
* *Confusing Code*: The presence of injection annotations on static fields can mislead developers into believing that the fields will be populated by Spring.

This rule raises an issue when a static will is annotated with @Value, @Inject, or @Autowired.
This rule raises an issue when a static field is annotated with @Value, @Inject, or @Autowired.

== How to fix it

Expand All @@ -23,7 +23,7 @@ Either use an instance field instead of a static field or remove the @Value, @In
public class MyComponent {
@Value("${my.app.prop}")
private static SomeDependency dependency; // Noncompliant, @Value will be ignored and no value will be injected
private static SomeDependency dependency; // non compliant, @Value will be ignored and no value will be injected
// ...
}
----
Expand Down

0 comments on commit e265d1f

Please sign in to comment.