FP Java S2693 Threads should not be started in constructors

  • Operating system: Windows
  • SonarQube for Eclipse plugin version: 10.11
  • Programming language you’re coding in: Java
  • Is connected mode used: No

The following code generates the warning. I think it should NOT since by definition the class is ‘final’ and the warning is not issued on final classes as appropraite.

            	        new Thread("name")
        		        {        	
        		            {
        		                setDaemon(true);
        		                start();
        		            }
                              }
        		      @Override	public void run()  { }

Hey @dandoy!

Thanks for the report. Can you provide a more complete code sample that reproduces the issue? Preferably a single file that includes the class definition.

package kevin;

public class FPTest {
    public static void main(String[] args)
	{
		new Thread("name")
	    {        	
	        {
	            setDaemon(true);
	            start();
	        }
	        @Override	public void run()  { return;}
	    };
	}
}

Hello @dandoy , thanks for reporting this issue.

I’m checking it myself, and I don’t get the rule S2693 triggered for that code, but I get S1171.

I’m using IntelliJ, SonarQube plugin 10.13

Could you please recheck and send a screenshot ?

My Company currently blocking sending/uploading screen capture. Here is the text from Sonar in my Eclipse IDE.

Description Resource Path Location Type

Move this “start” call to another method. FPTest.java /zKevin/src/kevin line 10 SonarLint Report Issue

By the way S1171 (we disabled) is also a FP when in an anonymous class since it cannot have a constructor.

Now I found that S2693 comes disabled by default. Now I get the same issue as you.
I’m investigating and I will come back with my findings.
Thanks for your patience.

Might as well get S1171 fixed also since it is generating a FP as you have shown, It should not give a positive on an anonymous class.

Any update on this?

Sorry for the delay @dandoy , we’ve been in an offsite the whole last week.
I will keep you posted.