@Incubating
class NullChecker
extends TypeCheckingDSL
A compile-time type checker that detects potential null dereferences and null-safety violations
in code annotated with @Nullable, @NonNull, and @MonotonicNonNull annotations.
By default, this checker performs annotation-based null checking only. For additional flow-sensitive
analysis that tracks nullability through assignments and control flow (even in unannotated code),
enable the strict option:
@TypeChecked(extensions = 'groovy.typecheckers.NullChecker(strict: true)')
Supported annotations are recognized by simple name from any package:
@Nullable, @CheckForNull, @MonotonicNonNull@NonNull, @NotNull, @NonnullDetected errors include:
null to a @NonNull variablenull or a @Nullable value to a @NonNull parameternull or a @Nullable value from a @NonNull method@Nullable variable without a null check or safe navigation (?.)@Nullable-returning method without a null checknull to a @MonotonicNonNull field after initializationstrict mode only)
The checker recognizes null guards (if (x != null)), early exit patterns
(if (x == null) return/throw), and safe navigation (?.).
@TypeChecked(extensions = 'groovy.typecheckers.NullChecker')
void process(@Nullable String input) {
// input.length() // error: potential null dereference
input?.length() // ok: safe navigation
if (input != null) {
input.length() // ok: null guard
}
}
Over time, the idea would be to support more cases as per:
https://checkerframework.org/manual/#nullness-checker
| Constructor and description |
|---|
NullChecker() |
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.