I have the below code for which Sonar Qube is raising a critical error.
public void onMessageReceived(Message message) {
if((message.getTargetInstanceId() != Message.ANY_TARGET) && (message.getTargetInstanceId() != this.instanceId)) {
//Invalid message ignore
return;
} else {
int randTime = ran.nextInt(2000);
FutureTask<Message> workerTask = new FutureTask<>(new DummyCommandHandler(randTime, message,messageBus,instanceId));
workerTask.run();
}
}
Below is the issue I am getting.
Description Assignee Resource New issue
Thread.run() and Runnable.run() should not be called directly : Call the method Thread.start() to execute the content of the run() method in a dedicated thread.
To call a start method in FutureTask, it doesn't have a start method in the first place. It only has a run method. How can I overcome this issue? Are there any Java solutions or Sonarqube solutions? Please advice.