aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes checkstyle help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "checkstyle help" Watch "checkstyle help" New topic
Author

checkstyle help

Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
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


SCJP 1.4 | SCWCD 1.4 | SCJD (WIP)
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
could you please paste the code for your class...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
I concur that it's much better to fix the code than to suppress the warning messages.


Ping & DNS - my free Android networking tools app
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
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

Joined: Apr 26, 2005
Posts: 516
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

Joined: Apr 26, 2005
Posts: 516
- 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

Joined: Sep 15, 2004
Posts: 94
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkstyle help