Skip to main content

avoid-non-final-exception-class-fields

added in: 1.22.0
Pro+

Warns when an exception class declaration has non-final fields.

Example

❌ Bad:

class CaughtException implements Exception {
final Object exception;

final String? message;

StackTrace stackTrace; // LINT

CaughtException(Object exception, StackTrace stackTrace)
: this.withMessage(null, exception, stackTrace);

CaughtException.withMessage(this.message, this.exception, this.stackTrace);
}

✅ Good:

class CaughtException implements Exception {
final Object exception;

final String? message;

final StackTrace stackTrace;

CaughtException(Object exception, StackTrace stackTrace)
: this.withMessage(null, exception, stackTrace);

CaughtException.withMessage(this.message, this.exception, this.stackTrace);
}