Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: UnusedVariable for record components that are not read directly #1648

Closed
anthonyvdotbe opened this issue May 30, 2020 · 4 comments

Comments

@anthonyvdotbe
Copy link
Contributor

Description of the problem / feature request:

A false positive for UnusedVariable is reported for all record components that are only read through methods.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

class Foo {

    record Bar(int v) {}

    int baz() {
        return new Bar(42).v();
    }

}

What version of Error Prone are you using?

2.4.0

Have you found anything relevant by searching the web?

No.

@ferozco
Copy link

ferozco commented Jun 12, 2020

We built a stricter version of UnusedVariable in gradle-baseline and we were able to make the rule compatible with records with this change which should be directly applicable to UnusedVariable

@codylerum
Copy link
Contributor

Same hit on this

Just the most simple record will fail

public record AgentAndCount(String agent, long count) {
}
Warning:  /home/runner/work/oss/oss/src/main/java/co/foo/oss/agent/AgentAndCount.java:[3,34] [UnusedVariable] The field 'agent' is never read.
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean 'public record AgentAndCount(, long count) {'?
Warning:  /home/runner/work/oss/oss/src/main/java/co/foo/oss/agent/AgentAndCount.java:[3,46] [UnusedVariable] The field 'count' is never read.
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean 'public record AgentAndCount(String agent) {'?

@tschniewind
Copy link

tschniewind commented Nov 18, 2022

Please reopen, cause it still failes if record is private as in

class Foo {

  private record Bar(int v) {
  }

  int baz() {
    return new Bar(42).v();
  }

}

com.google.errorprone.error_prone_core: 2.16
JDK 17, source & target 17

@nvervelle
Copy link

Please reopen, cause it still failes if record is private as in

This is why #2713 was opened :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants