rspec/rules/S1217/rule.adoc

28 lines
741 B
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
The purpose of the <code>Thread.run()</code> 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.
To get the expected behavior, call the <code>Thread.start()</code> method instead.
== 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://www.securecoding.cert.org/confluence/x/KQAiAg[CERT THI00-J.] - Do not invoke Thread.run()