All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2693.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

The problem with invoking Thread.start() in a constructor is that you'll have a confusing mess on your hands if the class is ever extended because the superclass' constructor will start the thread before the child class has truly been initialized.

This rule raises an issue any time start is invoked in the constructor of a non-final class.

Noncompliant Code Example

public class MyClass {

  Thread thread = null;

  public MyClass(Runnable runnable) {
    thread = new Thread(runnable);
    thread.start(); // Noncompliant
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy