Skip to content

False positives by UnusedVariable on unnamed variables (Java 22) #4451

@ksobolew

Description

@ksobolew

Compiling code like this:

var _ = someExpression();

Results in this report from Error Prone (2.28.0):

java: [UnusedVariable] The local variable '' is never read.
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean to remove this line?

This is a new feature in Java 22, which can be used to deliberately ignore a return value e.g. from methods declared as "must use return value". Note that the UnusedVariable check works fine in this case if the variable is called "ignored" or something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions