Exception classes should be immutable, that is, they should only have final fields. This is because 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.
public class MyException {
int nonFinalMember; // violation
}
|