Codenarc -Services stateless ruleSet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Codenarc -Services stateless ruleSet

pedrospaulus
Hi everybody, im trying  to use codeNarc on a grails project, after installing it and running it  i've have some rulesets violations messages that i would like to understand and resolve. The first on concern "GrailsStatelessService" and the second the  "equals() and  toString()" methods...

+For the first one "GrailsStatelessService" the message  i recieved is:
***************************
Violation in class app.TheServiceName. The class is marked as stateless but contains the non-final field 'aVariableName'
***************************
i've searched i little about that  but not found a lot of tricks about that..Can someone please explain me what the real meaning of this rulset and what ihave  to  do  to solve  this problem

+About the second kind of ruleSet  i found somewhere that it solved by overriding those  methods in all the  domain classes but is  that an obliguation, a need, or i just  have to modify the ruleSet File to avoid those kinds of messages related to those rulesets...
+And that introduce my  last question where to find  this ruleSet FIle( the default one within  codenarc) or the one i must include myself...?
thanks for advance...
Reply | Threaded
Open this post in threaded view
|

Re: Codenarc -Services stateless ruleSet

pledbrook
Administrator
> +For the first one "GrailsStatelessService" the message  i recieved is:
> ***************************
> Violation in class app.TheServiceName. The class is marked as stateless but
> contains the non-final field 'aVariableName'
> ***************************
> i've searched i little about that  but not found a lot of tricks about
> that..Can someone please explain me what the real meaning of this rulset and
> what ihave  to  do  to solve  this problem

I would consider disabling this ruleset. Services are singletons by
default, which means any instance variables are shared between all
threads. Ideally, service properties would be immutable (and final) so
that they can't be changed after the service is instantiated. However,
I think this will cause problems for Spring dependency injection.

The alternative is to add your properties to the list of field names
ignored by the ruleset. Or you can mark them as final. It really
depends on the class.

> +About the second kind of ruleSet  i found somewhere that it solved by
> overriding those  methods in all the  domain classes but is  that an
> obliguation, a need, or i just  have to modify the ruleSet File to avoid
> those kinds of messages related to those rulesets...

It's a recommendation. You might find this blog post interesting:
http://www.intelligrape.com/blog/tag/equals-grails-domain-class/

> +And that introduce my  last question where to find  this ruleSet FIle( the
> default one within  codenarc) or the one i must include myself...?

The plugin page describes how to configure your own ruleset files:
http://grails.org/plugin/codenarc

Hope that helps,

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware