Creator: Subhash Chandran
SF issue: 515
I am getting an unexpected checkstyle error in case of class names ending with the word “Error”. The error is “The field must be declared as final”. This error is reported for variables which could not be declared as final. Please see the below class.
public class SyncError
//Mutable Exception: The field 'message' must be declared final.
private String message;
If I am changing the class name such that it ends with any other string other than “Erorr” then this error is not reported by checkstyle.
Reason: checkstyle does not know anything about Types and their hierarchy. It deduce types by RegExp string to match Class name. Default regexp is "^._Exception$|^._Error$"
this Check will never be correct for that validation. All we could is improve a bit by checking that Class do extends of same name notation class ("an exception type must be a subclass of Throwable") and extend default value with "^.*Throwable$".
MutableException check requires class to explicitly extend some other…
… class (#60)
… class (for issue #60)
to make this Check useful and minimize amount of false-positives we need user defined properties for "format" and for "extendsClassNameFormat" default value is "^.Exception$|^.Error$|^.Throwable$" for both options.
Please update our xdoc files as we generate base on them our site - http://checkstyle.sourceforge.net/config_design.html#MutableException
fixed, will be released in 6.2
Doesn't look like this is fixed. I have the following and version 6.5 still complains about The field 'error' must be declared final.
The field 'error' must be declared final.
public class Error
private String error;
public Error withError(final String error)
this.error = error;
Renaming it to something else fixes the problem.
Please share your configuration for this check.
This is the config we use https://s3.amazonaws.com/unbounce-tools/java/ub-checkstyle.xml
So according to http://checkstyle.sourceforge.net/config_design.html#MutableException you use default exception class pattern which is ^.*Exception$|^.*Error$|^.*Throwable$. You can for example change it to ^.*Exception$|^.+Error$|^.*Throwable$, so that just Error won't be enforced to be mutable, but e.g. AssertionError will be.
I think you mean so that just Error won't be enforced to be immutable, but I see what you're saying. My understanding of the format property was wrong.