Re: [Codenarc-user] LoggerWithWrongModifiersRule supporting subclasses
Brought to you by:
chrismair
From: Chris M. <chr...@ea...> - 2011-05-31 01:48:08
|
That's a great question. I do use that pattern in framework superclasses: protected final LOG = Logger.getLogger(this.class) to provide a built-in logger for all subclasses. And so I have to configure exceptions for this rule for those superclasses. Is there any value in splitting up the "exception" configuration into two properties, if we do allow it? * allowNonStaticLogger * allowProtectedLogger Are there use cases we can envision where we (or anyone) would choose to allow non-static but not protected, or vice versa? Chris -----Original Message----- From: Hamlet D'Arcy [mailto:ham...@gm...] Sent: Monday, May 30, 2011 2:50 AM To: René Scheibe; Cod...@li... Subject: [Codenarc-user] LoggerWithWrongModifiersRule supporting subclasses Hi everyone, This email is about the idea about the LoggerWithWrongModifiersRule supporting subclasses. René filed an issue (and supplied a patch) describing the issue: https://sourceforge.net/tracker/index.php?func=detail&aid=3308930&group_id=2 50145&atid=1126575# Basically, the question is how subclasses should be allowed to access a Logger in a parent class. Normally Loggers are private, static, and final. This patch allows you to accept this as valid code when you turn a certain property on: protected final LOG = Logger.getLogger(this.class) I'd like to discuss this just a little more before committing the patch. With this change, it is acceptable to have a non-static logger. So each instance of a subclass makes and creates a logger. This does not seem right, and I would reject it in a code review as improper logging. I would accept this form though: protected static final LOG = Logger.getLogger(MyClass.class) Do we really want to allow non-static Loggers? if so, I recommend two new properties instead of just one: * allowNonStaticLogger * allowProtectedLogger Then the user can control the behavior a little better. -- Hamlet D'Arcy ham...@gm... ---------------------------------------------------------------------------- -- vRanger cuts backup time in half-while increasing security. With the market-leading solution for virtual backup and recovery, you get blazing-fast, flexible, and affordable data protection. Download your free trial now. http://p.sf.net/sfu/quest-d2dcopy1 _______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user |