Interface NullabilityResolver
- All Known Implementing Classes:
AnnotationBasedNullabilityResolver
Parameter is declared as accepting null.
Not every language expresses nullability through annotations that survive to runtime. Java typically uses a
Nullable annotation, which is read out of the box. Kotlin, on the other hand, encodes nullability in its
type system and compiles it to an annotation with RetentionPolicy.CLASS retention,
which reflection cannot observe. This interface exists so such languages can contribute their own resolution
without the framework depending on their tooling.
Implementations are discovered through the ServiceLoader mechanism, by declaring them in a
META-INF/services/org.axonframework.common.nullability.NullabilityResolver file, and are consulted in
descending Priority order. The first to return something other than
Nullability.UNKNOWN wins; implementations must report Nullability.UNKNOWN for parameters they know
nothing about, so that lower-priority resolvers, and finally the built-in annotation check, still get their turn.
Resolution happens while message handlers are being inspected, which is during application startup rather than per message. Implementations may therefore favor accuracy over speed, but must be thread-safe.
Marked Internal as the contract is still provisional. It is public only so that implementations shipping in
separate artifacts, such as the Kotlin extension, can reach it.
- Since:
- 5.3.0
- Author:
- Mateusz Nowak
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisNullable(Parameter parameter) Indicates whether the givenparameteris explicitly declared as acceptingnull.static NullabilitynullabilityOf(Parameter parameter) Determines the declaredNullabilityof the givenparameter, consulting everyNullabilityResolverfound on the classpath before falling back to the built-in annotation check.Determines the declaredNullabilityof the givenparameter.
-
Method Details
-
resolve
Determines the declaredNullabilityof the givenparameter.- Parameters:
parameter- the parameter to determine the nullability of- Returns:
- the declared nullability, or
Nullability.UNKNOWNwhen this resolver cannot tell
-
nullabilityOf
Determines the declaredNullabilityof the givenparameter, consulting everyNullabilityResolverfound on the classpath before falling back to the built-in annotation check.- Parameters:
parameter- the parameter to determine the nullability of- Returns:
- the declared nullability, or
Nullability.UNKNOWNwhen no resolver could tell
-
isNullable
Indicates whether the givenparameteris explicitly declared as acceptingnull.Note that a
falseresult covers both an explicitly non-null parameter and one whose nullability could not be determined. UsenullabilityOf(Parameter)to tell those apart.- Parameters:
parameter- the parameter to inspect- Returns:
trueif the parameter is explicitly declared as acceptingnull
-