rspec/rules/S1217/rule.adoc

29 lines
723 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
The purpose of the ``++Thread.run()++`` method is to execute code in a separate, dedicated thread. Calling this method directly doesn't make sense because it causes its code to be executed in the current thread.
2020-06-30 12:47:33 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
To get the expected behavior, call the ``++Thread.start()++`` method instead.
2020-06-30 12:47:33 +02:00
== Noncompliant Code Example
----
Thread myThread = new Thread(runnable);
myThread.run(); // Noncompliant
----
== Compliant Solution
----
Thread myThread = new Thread(runnable);
myThread.start(); // Compliant
----
== See
* http://cwe.mitre.org/data/definitions/572.html[MITRE, CWE-572] - Call to Thread run() instead of start()
* https://wiki.sei.cmu.edu/confluence/x/6DdGBQ[CERT THI00-J.] - Do not invoke Thread.run()
2020-06-30 12:47:33 +02:00