Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve Java Checkstyle Error: Name 'logger' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'

Using the Eclipse Checkstyle plugin I see this error:

Name 'logger' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

I resolved this error by changing:

private static final Logger logger = Logger.getLogger(someClass.class);

to

private static final Logger LOGGER = Logger.getLogger(someClass.class);

Why is this a checkstyle warning?

like image 397
javaPlease42 Avatar asked Dec 12 '14 20:12

javaPlease42


2 Answers

Because the field is marked final and static which implies that it's a constant and should be named with uppercase letters.

From this link, you can see that the module ConstantName has the format ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ which is exactly the one your Checkstyle plugin has specified.

like image 114
M A Avatar answered Nov 17 '22 09:11

M A


The documentation recommends using this configuration if you wish to keep logger as a valid option:

<module name="ConstantName">
  <property name="format"
    value="^log(ger)?$|^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
    
like image 5
lightswitch05 Avatar answered Nov 17 '22 09:11

lightswitch05