Why is this an issue?

The Thread class has some methods that are used to monitor and manage its execution. With the introduction of virtual threads in Java 21, there are three of these methods that behave differently between the standard platform threads and the virtual ones.

For virtual threads:

This rule reports an issue when one of these methods is invoked on a virtual thread.

Code examples

Noncompliant code example

Thread t = Thread.ofVirtual().unstarted(()->{/* some task */});
t.setPriority(1); // Noncompliant; virtual threads' priority cannot be changed
t.setDaemon(false); // Noncompliant; will throw IllegalArgumentException
t.setDaemon(true); // Noncompliant; redundant
t.start();
var threadGroup = t.getThreadGroup(); // Noncompliant; virtual thread groups should not be used

Resources

Documentation