Class MutableExceptionCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public final class MutableExceptionCheck
    extends AbstractCheck

    Ensures that exceptions (classes with names conforming to some regular expression and explicitly extending classes with names conforming to other regular expression) are immutable. That is, they 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