Class MutableExceptionCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.design.MutableExceptionCheck
- All Implemented Interfaces:
- Configurable,- Contextualizable
 Ensures that exception classes (classes with names conforming to some pattern
 and explicitly extending classes with names conforming to other
 pattern) are immutable, that is, that they have only final fields.
 
 
 The current algorithm is very simple: it checks that all members of exception are final.
 The user can still mutate an exception's instance (e.g. Throwable has a method called
 setStackTrace which changes the exception's stack trace). But, at least, all
 information provided by this exception type is unchangeable.
 
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 set the initial state. In both cases, code catching the exception could draw incorrect conclusions based on the state.
- Since:
- 3.2
- 
Nested Class SummaryNested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate booleanShould we check current class or not.Stack of checking information for classes.private static final StringDefault value for format and extendedClassNameFormat properties.private PatternSpecify pattern for extended class names.private PatternSpecify pattern for exception class names.static final StringA key is pointing to the warning message text in "messages.properties" file.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionint[]The configurable token set.int[]Returns the default token a check is interested in.int[]The tokens that this check must be registered for.private booleanChecks that if extended class name conforms to specified format.private booleanChecks that a class name conforms to specified format.private voidCalled when we leave class definition.voidleaveToken(DetailAST ast) Called after all the child nodes have been process.voidsetExtendedClassNameFormat(Pattern extendedClassNameFormat) Setter to specify pattern for extended class names.voidSetter to specify pattern for exception class names.private voidvisitClassDef(DetailAST ast) Called when we start processing class definition.voidvisitToken(DetailAST ast) Called to process a token.private voidChecks variable definition.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheckbeginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporterfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfiguration, setupChild
- 
Field Details- 
MSG_KEYA key is pointing to the warning message text in "messages.properties" file.- See Also:
 
- 
DEFAULT_FORMATDefault value for format and extendedClassNameFormat properties.- See Also:
 
- 
checkingStackStack of checking information for classes.
- 
extendedClassNameFormatSpecify pattern for extended class names.
- 
checkingShould we check current class or not.
- 
formatSpecify pattern for exception class names.
 
- 
- 
Constructor Details- 
MutableExceptionCheckpublic MutableExceptionCheck()
 
- 
- 
Method Details- 
setExtendedClassNameFormatSetter to specify pattern for extended class names.- Parameters:
- extendedClassNameFormat- a- Stringvalue
- Since:
- 6.2
 
- 
setFormatSetter to specify pattern for exception class names.- Parameters:
- pattern- the new pattern
- Since:
- 3.2
 
- 
getDefaultTokensDescription copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
- getDefaultTokensin class- AbstractCheck
- Returns:
- the default tokens
- See Also:
 
- 
getRequiredTokensDescription copied from class:AbstractCheckThe tokens that this check must be registered for.- Specified by:
- getRequiredTokensin class- AbstractCheck
- Returns:
- the token set this must be registered for.
- See Also:
 
- 
getAcceptableTokensDescription copied from class:AbstractCheckThe configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Specified by:
- getAcceptableTokensin class- AbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
 
- 
visitTokenDescription copied from class:AbstractCheckCalled to process a token.- Overrides:
- visitTokenin class- AbstractCheck
- Parameters:
- ast- the token to process
 
- 
leaveTokenDescription copied from class:AbstractCheckCalled after all the child nodes have been process.- Overrides:
- leaveTokenin class- AbstractCheck
- Parameters:
- ast- the token leaving
 
- 
visitClassDefCalled when we start processing class definition.- Parameters:
- ast- class definition node
 
- 
leaveClassDefCalled when we leave class definition.
- 
visitVariableDefChecks variable definition.- Parameters:
- ast- variable def node for check
 
- 
isNamedAsExceptionChecks that a class name conforms to specified format.- Parameters:
- ast- class definition node
- Returns:
- true if a class name conforms to specified format
 
- 
isExtendedClassNamedAsExceptionChecks that if extended class name conforms to specified format.- Parameters:
- ast- class definition node
- Returns:
- true if extended class name conforms to specified format
 
 
-