-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: update java/call-to-thread-run
#19175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
java/ql/src/Likely Bugs/Concurrency/RunMethodCalledOnJavaLangThreadDirectly.ql
Fixed
Show fixed
Hide fixed
...-tests/RunMethodCalledOnJavaLangThreadDirectly/RunMethodCalledOnJavaLangThreadDirectly.qlref
Fixed
Show fixed
Hide fixed
72e089f
to
67b93dd
Compare
QHelp previews: java/ql/src/Likely Bugs/Concurrency/CallsToRunnableRun.qhelpDirect call to a run() methodA direct call of a RecommendationTo execute
ExampleIn the following example, the main thread, public class ThreadDemo {
public static void main(String args[]) {
NewThread runnable = new NewThread();
runnable.run(); // Call to 'run' does not start a separate thread
System.out.println("Main thread activity.");
}
}
class NewThread extends Thread {
public void run() {
try {
Thread.sleep(10000);
}
catch (InterruptedException e) {
System.out.println("Child interrupted.");
}
System.out.println("Child thread activity.");
}
} To enable the two threads to run concurrently, create the child thread and call public class ThreadDemo {
public static void main(String args[]) {
NewThread runnable = new NewThread();
runnable.start(); // Call 'start' method
System.out.println("Main thread activity.");
}
} References
|
67b93dd
to
3866cfc
Compare
3866cfc
to
a0bb0e2
Compare
using existing query java/call-to-thread-run instead
a0bb0e2
to
4290411
Compare
cc @knewbury01 |
Thread.run()
java/call-to-thread-run
Description
Minor updates to the pre-existing
java/call-to-thread-run
quality query based on the similarjava/run-method-called-on-java-lang-thread-directly
query from the services team's quality queries.Specifically:
@previous-id
to reference the services queryConsideration
Changes from the services team's query. Let me know if you disagree with any of these changes:
performance
tag from the services query.run
within arun
method from the existing query. This exclusion was not in the services team's query.java.lang.Thread
import statement from the services team's query. Sincejava.lang
classes do not need to be explicitly imported, the reliance on the existence of this import statement was causing FNs.Alert count notes:
java.lang.Thread
import statement requirement.java/run-method-called-on-java-lang-thread-directly
: 8 alertsjava/call-to-thread-run
: 62 alertsjava/run-method-called-on-java-lang-thread-directly
: 18 alertsjava/call-to-thread-run
: 161 alertsOther Notes:
run()
withstart()
as recommended by the qhelp.