rspec/rules/S2693/rule.adoc

26 lines
707 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue any time ``++start++`` is invoked in the constructor of a non-``++final++`` class.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
----
public class MyClass {
Thread thread = null;
public MyClass(Runnable runnable) {
thread = new Thread(runnable);
thread.start(); // Noncompliant
}
}
----
== See
* https://wiki.sei.cmu.edu/confluence/x/FDdGBQ[CERT, TSM02-J.] - Do not use background threads during class initialization
2020-06-30 12:48:07 +02:00