This class has been annotated with the annotation Immutable, from the JCIP annotations package. However, one of the mutable fields of the class had a mutating method called on it outside of the constructor and destructor.
Example 1: The following code for an immutable final class mistakenly declares a Set public
and final
.
@Immutable
public final class ThreeStooges {
private final Set stooges = new HashSet>();
...
public void addStooge(String name) {
stooges.add(name);
}
}
[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 471
[2] B. Goetz Java Concurrency in Practice. Chapter 3: Sharing Objects Guidelines
[3] Package net.jcip.annotations Specification