Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: REM cost reform

Invariants cannot be enforced for public nonfinal fields or for final fields that reference a mutable object. A protected member of an exported (non-final) class represents a public commitment to an implementation detail. Attackers can manipulate such fields to violate class invariants, or they may be corrupted by multiple threads accessing them concurrently [Bloch 2008]. As a result, fields must be declared private or package-private.

...

Failing to limit field accessibility can defeat encapsulation, allow attackers to manipulate fields to violate class invariants, or allow these fields to be corrupted as the result of concurrent accesses from multiple threads.

Rule

Severity

Likelihood

Detectable

Remediation CostRepairable

Priority

Level

OBJ01-J

Medium

Likely

No

MediumNo

P12P6

L1L2

Automated Detection

Detection of public and protected fields is trivial; heuristic detection of the presence or absence of accessor methods is straightforward. However, simply reporting all detected cases without suppressing those cases covered by the exceptions to this rule would produce excessive false positives. Sound detection and application of the exceptions to this rule is infeasible; however, heuristic techniques may be useful.

ToolVersionCheckerDescription
Klocwork

Include Page
Klocwork_V
Klocwork_V

SV.EXPOSE.MUTABLEFIELD
SV.EXPOSE.FIELD
SV.EXPOSE.IFIELD
SV.STRUTS.PRIVATE
SV.STRUTS.STATIC

 

SonarQube
Include Page
SonarQube_V
SonarQube_V
S2386

Mutable fields should not be "public static"

Implemented for public static array, Collection, Date, and awt.Point members.

...