Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Parasoft Jtest 2022.2

...

The resulting behavior can be classified as shadowing; the method variable renders the class instance variable inaccessible within the scope of the method. For example, assigning to this.val from within the method does not affect the value of the call instance variable, although assigning to this.val from within the method does.

Compliant Solution (Field Shadowing)

...

Name reuse makes code more difficult to read and maintain, which can result in security weaknesses. An automated tool can easily detect reuse of identifiers in containing scopes.

Automated Detection

ToolVersionCheckerDescription
Parasoft Jtest

Include Page
Parasoft_V
Parasoft_V

CERT.DCL51.HMFDo not give method local variables and parameters the same name as class fields
SonarQube
Include Page
SonarQube_V
SonarQube_V
HiddenFieldCheck


Bibliography

[Bloch 2005]

Puzzle 67, "All Strung Out"

[Bloch 2008]

Item 16, "Prefer Interfaces to Abstract Classes"

[Conventions 2009]

§6.3, "Placement"

[FindBugs 2008]

 


[JLS 2013]

§6.4.1, "Shadowing"
§6.4.2, "Obscuring"

§7.5.2, "Type-Import-on-Demand Declarations"

...


...

Image Modified Image Modified Image Modified