An instance is built just to read its Class object

tx0/java:class-of-new-instancerecommendedwarningperformance

What it finds

new Parser().getClass() builds a whole object, with whatever its constructor does, to get a Class that the literal Parser.class names directly.

Reported is getClass() called on an instance creation without a class body.

From the rule's source, class_of_new_instance.rs.

Example from the rule's tests
class Types {  Class<?> kind() {    Class<?> a = new StringBuilder().getClass();tx0 reports: a class literal names it    return StringBuilder.class;  }}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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

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