-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SONARJAVA-5284 Create rule S7178: Injecting data into static fields is not supported by Spring #4611
base: master
Are you sure you want to change the base?
Conversation
rules/S7178/java/metadata.json
Outdated
"impacts": { | ||
"MAINTAINABILITY": "HIGH", | ||
"RELIABILITY": "HIGH", | ||
"SECURITY": "LOW" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that the issue mostly impacts reliability, as the code will not behave as intended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
rules/S7178/java/rule.adoc
Outdated
|
||
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the potential impact? | |
=== What is the potential impact? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
rules/S7178/java/rule.adoc
Outdated
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch 👍
rules/S7178/java/rule.adoc
Outdated
public class MyComponent { | ||
|
||
@Value("${my.app.prop}") | ||
private static SomeDependency dependency; // Noncompliant, @Value will be ignored and no value will be injected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Quality Gate passed for 'rspec-tools'Issues Measures |
Quality Gate passed for 'rspec-frontend'Issues Measures |
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: