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

廉价感情. 提交于 2019-12-10 13:38:00

问题


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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/27451395/resolve-java-checkstyle-error-name-logger-must-match-pattern-a-za-z0-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!