2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
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")++``
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@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
...
}
----
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Make "xxx" static, remove it, or give the class "prototype" scope.
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== 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.
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]