Skip to content

Commit c41665b

Browse files
committed
PMD: AvoidUnmanagedThreads
1 parent ae6bea8 commit c41665b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

.config/pmd/java/ruleset.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,28 @@
218218
</properties>
219219
</rule>
220220

221+
<rule name="AvoidUnmanagedThreads"
222+
language="java"
223+
message="Avoid unmanaged threads"
224+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
225+
<description>
226+
Trying to manually manage threads usually gets quickly out of control and may result in various problems like uncontrollable spawning of threads.
227+
Threads can also not be cancelled properly.
228+
229+
Use managed Thread services like ``ExecutorService`` and ``CompletableFuture`` instead.
230+
</description>
231+
<priority>3</priority>
232+
<properties>
233+
<property name="xpath">
234+
<value>
235+
<![CDATA[
236+
//MethodCall[pmd-java:matchesSig('java.lang.Thread#start()') or pmd-java:matchesSig('java.lang.Thread#startVirtualThread(java.lang.Runnable)') or pmd-java:matchesSig('java.lang.Thread$Builder#start(java.lang.Runnable)')]
237+
]]>
238+
</value>
239+
</property>
240+
</properties>
241+
</rule>
242+
221243
<rule name="JavaObjectSerializationIsUnsafe"
222244
language="java"
223245
message="Using Java Object (De-)Serialization is unsafe and has led to too many security vulnerabilities"

0 commit comments

Comments
 (0)