rspec/rules/S2213/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

66 lines
1.4 KiB
Plaintext

== Why is this an issue?
A Spring ``++singleton++`` bean may be used by many threads at once, and the use of instance (non-``++static++``) variables could cause concurrency issues.
This rule applies to classes with the following annotations: ``++@Service++``, ``++@Component++``, ``++@Repository++``, ``++@Scope("singleton")++``
=== Noncompliant code example
[source,java]
----
@Service("animalService")
public class AnimalService {
private int age = 1; // Noncompliant
private static int count = 0; // Compliant; static
@Inject
private AnimalDAO animalDAO; // Compliant; managed by Spring
...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make "xxx" static, remove it, or give the class "prototype" scope.
'''
== Comments And Links
(visible only on this page)
=== on 2 Mar 2018, 14:15:29 Alexandre Gigleux wrote:
\[~ann.campbell.2] This RSPEC is obsolete because better described RSPEC-3749 and already implemented by SONARJAVA-2168.
Shall we simply "Close Won't Fix" this RSPEC or delete it?
=== on 2 Mar 2018, 15:14:59 Ann Campbell wrote:
\[~alexandre.gigleux] the scope is slightly different:
||this||RSPEC-3749||
|@Service|@Service|
|@Component| |
|@Repository|@Repository|
|@Scope("singleton")| |
| |@Controller|
Should the missing elements be added to RSPEC-3749 or just dropped? Either way, I'm fine to Won't-Fix this.
endif::env-github,rspecator-view[]