Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

EI_EXPOSE_REP and EI_EXPOSE_REP2 failures when using Immutable objects from Guava. How should this be corrected? #113

Open
callum-kilby opened this issue Jul 2, 2021 · 3 comments

Comments

@callum-kilby
Copy link

We are using Guava Immutable objects in our project, and from SpotBugs 4.3.0 we have SpotBugs failures EI_EXPOSE_REP and EI_EXPOSE_REP2 when directly setting/retrieving class fields as Immutable objects.

For example:

private Map<String, String> overrides;

public CLISetup(String commandLine, ImmutableMap<String, String> overrides) {
    this.commandLine = commandLine;
    this.overrides = overrides;
}

results in an EI_EXPOSE_REP2 failure from this.overrides = overrides.

This failure is incorrect because the object being passed in and set for the class field is shallowly immutable. What can be done to fix these failures? I'm hoping we don't need to completely exclude EI_EXPOSE_REP and EI_EXPOSE_REP2, or annotate everywhere we do something like this.

@baloghadamsoftware
Copy link

Thank you for your report, I will add ImmutableMap & co. to the list of immutable objects. (Unfortunately I cannot assign this bug to myself since I am not yet an official project member.)

@baloghadamsoftware
Copy link

Just a side note: Either make this an issue (https://github.com/spotbugs/spotbugs/issues) or move this discussion to here: https://github.com/spotbugs/spotbugs/discussions.

@callum-kilby
Copy link
Author

👍 thanks very much, I've created an issue with the same description here:
spotbugs/spotbugs#1601

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

No branches or pull requests

2 participants