A method calls itself before anything else runs, so it never returns
What it finds
A method whose body calls the method itself before anything else can happen never returns: each call starts the next, until the stack overflows. This is usually a call that was meant for a field, a delegate or the superclass, as in size() { return size(); } where list.size() or super.size() was meant.
Reported is a call of the method's own name that passes the method's own parameters unchanged and in order, so that it cannot mean another overload, on no receiver, on this or on the class's own name for a static method, in one of the statements that open the body and always run: expression statements, declarations and return, up to the first statement that may branch. The call must not sit in a branch of a conditional expression, the right side of && or ||, a lambda or a class body. Methods with variable arity are left alone.
From the rule's source, unconditional_self_call.rs.
import java.util.List; class Wrapper { private final List<String> items; Wrapper(List<String> items) { this.items = items; } int size() { return size();tx0 reports: starts the method over } boolean isEmpty() { String note = describe(); return this.isEmpty();tx0 reports: starts the method over } static int depth(int n) { return Wrapper.depth(n);tx0 reports: starts the method over } int count(int n) { if (n == 0) { return 0; } return count(n - 1); } int total() { return items.isEmpty() ? 0 : total(); } String describe() { return items.toString(); } int find(String key) { return find(key, 0); } int find(String key, int from) { return items.indexOf(key) + from; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:unconditional-self-call" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:unconditional-self-call] reason="..."tx0 explain tx0/java:unconditional-self-call shows the same in the terminal. Found a false positive? Report it.