Skip to content

UnusedVariable sometimes gives false positives for record parameters #2713

Closed
trinodb/trino
#19129
@dododge

Description

@dododge

Using error-prone 2.10.0.

Here's a trivial example of a record where I get a warning that the x value is never being used, even though there are public methods that access it both directly and via its getter.

public class Example
{
    private static record MyRecord(int x) { }

    public static int testMethod1(int x) {
        return new MyRecord(x).x();
    }

    public static int testMethod2(int x) {
        return new MyRecord(x).x;
    }
}
Example.java:[3,12] [UnusedVariable] The parameter 'x' is never read.

I don't know the exact conditions that trigger this, but for example if I make the record itself public the warning goes away.

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