Nothing in its file calls a private method
What it finds
A private method that nothing calls is dead code: it has to be read, compiled and kept working, for nothing.
A method counts as used when its name occurs anywhere else in the file, as an identifier, which covers calls, method references and overloads, or as the whole of a string literal, as reflection and test frameworks name methods. Left alone are methods with annotations, the private methods that serialization calls (writeObject, readObject, readObjectNoData, writeReplace, readResolve), and files that use Lombok or declare native methods.
From the rule's source, unused_private_method.rs.
import java.io.ObjectInputStream;import java.util.List; class Parser { List<String> parse(List<String> lines) { lines.forEach(this::check); return lines; } private void check(String line) {} private void legacy() {}tx0 reports: the private method legacy is never called private void readObject(ObjectInputStream in) {} @Deprecated private void annotated() {}} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:uncalled-private-method" = "warning"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:uncalled-private-method] reason="..."tx0 explain tx0/java:uncalled-private-method shows the same in the terminal. Found a false positive? Report it.