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 EI_EXPOSE_REP when using List.copyOf #2117

Closed
josephearl opened this issue Jul 19, 2022 · 4 comments
Closed

False positive EI_EXPOSE_REP when using List.copyOf #2117

josephearl opened this issue Jul 19, 2022 · 4 comments

Comments

@josephearl
Copy link

Given the following class:

public class Test {
  private List<Integer> ints;

  public Test2(List<Integer> ints) {
    this.ints = List.copyOf(ints);
  }

  public List<Integer> getInts() {
    return ints;
  }
}

SpotBugs raises a warning EI_EXPOSE_REP because Test.getInts() may expose internal representation by returning Test.ints

However since List.copyOf creates an unmodifiable list, no mutable internal representation is returned and this is a false positive.

@welcome
Copy link

welcome bot commented Jul 19, 2022

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@osiegmar
Copy link

osiegmar commented Aug 8, 2022

Similar to #1771

@baloghadamsoftware
Copy link
Contributor

#2141 should fix this as well. Please confirm that the issue is resolved in Sputbugs version 4.7.2.

@josephearl
Copy link
Author

Can confirm, updated yesterday and was able to remove the suppressions we had

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

No branches or pull requests

3 participants