This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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: 63227

Moved to IDEs and other tools.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: checkstyle and hidden field?
It's not a secret anymore!