A class with only static members has an implicit public constructor

tx0/java:instantiable-utility-classstrictwarningsmell

What it finds

A class whose members are all static and that declares no constructor still gets the implicit public one: callers can create instances that serve no purpose, and the class reads as if it were meant to be instantiated. A private constructor says it is not.

Reported for top-level and non-private nested classes with at least one static method, only static members, no constructor, and no extends or implements clause. Classes with a main method, which are programs rather than holders, and annotated classes, which frameworks may instantiate, are left alone.

From the rule's source, instantiable_utility_class.rs.

Example from the rule's tests
class Strings {tx0 reports: Strings has only static members but can be instantiated  static final String EMPTY = "";   static boolean blank(String s) {    return s == null || s.isBlank();  }} class Hidden {  private Hidden() {}   static int one() {    return 1;  }} class Mixed {  int value;   static int two() {    return 2;  }} class Tool {  public static void main(String[] args) {}} @Deprecatedclass Old {  static int three() {    return 3;  }} class Outer {  private Outer() {}   static class Helpers {tx0 reports: Helpers has only static members but can be instantiated    static int four() {      return 4;    }  }   private static class Private {    static int five() {      return 5;    }  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/java:instantiable-utility-class" = "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:instantiable-utility-class] reason="..."

tx0 explain tx0/java:instantiable-utility-class shows the same in the terminal. Found a false positive? Report it.