ABSTRACT

The class is annotated as immutable, but field is mutated at line in file .

EXPLANATION

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);
}

}

REFERENCES

[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