A void method is named like its class, so it is not the constructor it looks like
What it finds
public void Account() { ... } in class Account is a method, not a constructor: the return type makes it one. new Account() runs the implicit constructor and never this code. Usually the return type was added by mistake.
Reported are methods without parameters, named exactly like their class, that return void and are not native; a method that returns a value or takes parameters under the class's name is often deliberate, as in factories and the entry points of native loops.
From the rule's source, method_named_like_class.rs.
class Account { private int balance; public void Account() {tx0 reports: Account is a method, not a constructor balance = 10; } public static Account Account(int b) { return new Account(); }} 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:method-named-like-class" = "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:method-named-like-class] reason="..."tx0 explain tx0/java:method-named-like-class shows the same in the terminal. Found a false positive? Report it.