File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes IDEs, Version Control and other tools and the fly likes checkstyle and hidden field? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "checkstyle and hidden field?" Watch "checkstyle and hidden field?" New topic

checkstyle and hidden field?

keith doyle

Joined: Jan 25, 2005
Posts: 15
I'm running checkstyle and its complaining that a local variable "hides a field."
The checkstyle API says:
"Checks that a local variable or a parameter does not shadow a field that is defined in the same class."

I don't understand this - what is a field? Can someone give me a simple example of this problem.
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234

I don't use checkstyle at the moment but I guess the following is happening

The second index is hiding the first one. Which can be confusing at times.
keith doyle

Joined: Jan 25, 2005
Posts: 15
OK I figured it out basically checkStyle doesn't like the parameter name to be the same name as the local variable in a setter method. i.e.

Personally, I like this approch, you can disable this check in sun_checks.xml using the following :
keith doyle

Joined: Jan 25, 2005
Posts: 15
Thanks Bart!
FYI - I tested for the condition you explained and this will also create the complaint.
Happy Days...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Moved to IDEs and other tools.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: checkstyle and hidden field?
It's not a secret anymore!