• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checkstyle help

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers-

I am seeing the following warnings from checkstyle in my contractor class. Basically my contractor class has fields and get/set methods.

--I got this message for a getmethod
Method XYZ is not designed for extension - needs to be abstract, final or empty.

--I got this message for a constructor with args
parameter hides a field

Can somebody tell me how to configure checkstyle to avoid these messages.

thanks,

Harish
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you please paste the code for your class...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I concur that it's much better to fix the code than to suppress the warning messages.
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this method, I am getting
method getLocation is not designed for extension - needs to be abstract, final or empty



for this contructor code see below, I am getting several messages like
-location hides a field
-location should be final
similar messages for status, recNo, name

 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Harish Yerneni:



I think it looks at the variables received as parameters: (Contractor(final int status, final int recNo, final String name, final String location, final String specialties, final String size, final String rate, final String owner).

I don't know if that's the best/preferred style however.
For the other method, I don't know, but try playing around with similar cause.

Regards,
Alex
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- http://www.docjar.net/docs/api/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.html


Checks that classes are designed for inheritance.

More specifically, it enforces a programming style where superclasses provide empty "hooks" that can be implemented by subclasses.

The exact rule is that nonprivate, nonstatic methods in nonfinal classes (or classes that do not only have private constructors) must either be

abstract or
final or
have an empty implementation

This protects superclasses against beeing broken by subclasses. The downside is that subclasses are limited in their flexibility, in particular they cannot prevent execution of code in the superclass, but that also means that subclasses can't forget to call their super method.


- http://www.docjar.net/docs/api/com/puppycrawl/tools/checkstyle/checks/HiddenFieldCheck.html


Checks that a local variable or a parameter does not shadow a field that is defined in the same class.


- http://www.docjar.net/docs/api/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.html


Check that method/constructor parameters are final. The user can set the token set to METHOD_DEF, CONSTRUCTOR_DEF, or both (default), to control the scope of this check.

 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Alex. The second problem with "hide" messages went away when I change the method parameter names to something different than class member variable names.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic