java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.Check
com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck
com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck
- All Implemented Interfaces:
- com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable
- public final class MutableExceptionCheck
- extends com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck
Ensures that exceptions (defined as any class name conforming
to some regular expression) are immutable. That is, have only final
fields.
Rationale: Exception instances should represent an error
condition. Having non final fields not only allows the state to be
modified by accident and therefore mask the original condition but
also allows developers to accidentally forget to initialise state
thereby leading to code catching the exception to draw incorrect
conclusions based on the state.
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check |
|
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
|
| Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check |
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getTabWidth, getTokenNames, init, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_FORMAT
private static final java.lang.String DEFAULT_FORMAT
- Default value for format property.
- See Also:
- Constant Field Values
mCheckingStack
private final java.util.Stack mCheckingStack
- Stack of checking information for classes.
mChecking
private boolean mChecking
- Should we check current class or not.
MutableExceptionCheck
public MutableExceptionCheck()
- Creates new instance of the check.
getDefaultTokens
public int[] getDefaultTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- Returns the default token a check is interested in. Only used if the
configuration for a check does not define the tokens.
getRequiredTokens
public int[] getRequiredTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- The tokens that this check must be registered for.
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- Called to process a token.
leaveToken
public void leaveToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- Called after all the child nodes have been process.
visitClassDef
private void visitClassDef(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Called when we start processing class definition.
leaveClassDef
private void leaveClassDef()
- Called when we leave class definition.
visitVariableDef
private void visitVariableDef(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Checks variable definition.
isExceptionClass
private boolean isExceptionClass(java.lang.String aClassName)