Java – checkstyle reports a localfinalvariablenamecheck error for the catch exception parameter
I have a strange question, I'm not sure if it's a problem between the two ears or a checkstyle one
LocalFinalVariableNameCheck,Priority: Normal Name 'pEx' must match pattern '^l[A-Z][a-zA-Z0-9]*$'.
This is the code
... } catch (final XPathExpressionException pEx) { throw new ConfigurationException(pEx); }
Why does checkstyle define catch blocks as local var instead of param?
Solution
As @ Dongqing pointed out, PEX is indeed a local variable, so the check here applies
However, it should be noted that the default value of this rule is ^ [A-Z] [a-za-z0-9] * $, as specified in the latest version of the tool The pattern you may have customized is suitable for some local standards ^ l [A-Z] [a-za-z0-9] * $ Therefore, before deleting the violation, you should ensure that the naming pattern is indeed normal (why define a custom rule if it is not appropriate?)
If you really want to get rid of this violation, checkstyle provides various methods to suppress warnings You can:
>Using the suppression XML file allows you to suppress specific rules on a specific file for a given range of rows (or even column ranges) This way, you don't have to modify the code, but you need to use all suppression to maintain a separate file. > Use comments or comments to disable warnings by adding comments or comments to your code, such as @ suppresswarnings, where false positives are This must also be configured For details and examples, see the links above
Edit: this checkstyle rule also allows you to adjust the mode of variable declarations or catch clauses The following configuration should suit you:
<module name="LocalVariableName"> <property name="format" value="^[a-zA-Z0-9]*$"/> <property name="tokens" value="PARAMETER_DEF"/> </module>
Here, you only specify a very tolerant pattern for violations in the catch clause Variable declarations should not be affected and the original schema still needs to be checked