com.puppycrawl.tools.checkstyle.checks.design

Class MutableExceptionCheck

Implemented Interfaces:
Configurable, Contextualizable

public final class MutableExceptionCheck
extends 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.

Author:
Simon Harris

Constructor Summary

MutableExceptionCheck()
Creates new instance of the check.

Method Summary

int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
leaveToken(DetailAST aAST)
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck

getFormat, getRegexp, setCompileFlags, setFormat

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getId, getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setId, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

MutableExceptionCheck

public MutableExceptionCheck()
Creates new instance of the check.

Method Details

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

getRequiredTokens

public int[] getRequiredTokens()
Overrides:
getRequiredTokens in interface Check

leaveToken

public void leaveToken(DetailAST aAST)
Overrides:
leaveToken in interface Check

visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check