rspec/rules/S1217/java/rule.adoc

29 lines
723 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02: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.
To get the expected behavior, call the ``++Thread.start()++`` method instead.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
Thread myThread = new Thread(runnable);
myThread.run(); // Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
Thread myThread = new Thread(runnable);
myThread.start(); // Compliant
----
2021-04-28 16:49:39 +02:00
== 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()