A method or constructor takes an Optional parameter
What it finds
Optional is meant for return values that may be missing. As a parameter it gives callers three cases to pass instead of two (null, empty, a value), and wraps every argument. Overloads, or a nullable parameter, express the same more simply.
Methods marked @Override are left alone, since their parameters are not theirs to choose.
From the rule's source, optional_parameter.rs.
import java.util.Optional; class Search { void find(String query, Optional<Integer> limit) {}tx0 reports: this parameter is an Optional Optional<String> first(String query) { return Optional.empty(); }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:optional-in-signature" = "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:optional-in-signature] reason="..."tx0 explain tx0/java:optional-in-signature shows the same in the terminal. Found a false positive? Report it.