[Codenarc-user] LoggerWithWrongModifiersRule supporting subclasses
Brought to you by:
chrismair
From: Hamlet D'A. <ham...@gm...> - 2011-05-30 06:49:40
|
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=250145&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... |