A NullPointerException is caught instead of checking for null
What it finds
catch (NullPointerException e) treats a programming error as an expected outcome: it hides the real defect, a missing check for null, and catches every other dereference of null in the block too.
From the rule's source, catch_null_pointer.rs.
class Names { int length(String name) { try { return name.length(); } catch (NullPointerException e) {tx0 reports: a NullPointerException is caught return 0; } } int size(java.util.List<String> names) { try { return names.size(); } catch (IllegalStateException | NullPointerException e) {tx0 reports: a NullPointerException is caught return 0; } catch (RuntimeException e) { return -1; } }} 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:catch-null-pointer" = "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:catch-null-pointer] reason="..."tx0 explain tx0/java:catch-null-pointer shows the same in the terminal. Found a false positive? Report it.