rspec/rules/S2693/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

41 lines
947 B
Plaintext

== Why is this an issue?
The problem with invoking ``++Thread.start()++`` in a constructor is that you'll have a confusing mess on your hands if the class is ever extended because the superclass' constructor will start the thread before the child class has truly been initialized.
This rule raises an issue any time ``++start++`` is invoked in the constructor of a non-``++final++`` class.
=== Noncompliant code example
[source,java]
----
public class MyClass {
Thread thread = null;
public MyClass(Runnable runnable) {
thread = new Thread(runnable);
thread.start(); // Noncompliant
}
}
----
== Resources
* https://wiki.sei.cmu.edu/confluence/x/FDdGBQ[CERT, TSM02-J.] - Do not use background threads during class initialization
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this "start" call to another method.
endif::env-github,rspecator-view[]