Interface NullabilityResolver

All Known Implementing Classes:
AnnotationBasedNullabilityResolver

@Internal public interface NullabilityResolver
Determines whether a 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 Type
    Method
    Description
    static boolean
    isNullable(Parameter parameter)
    Indicates whether the given parameter is explicitly declared as accepting null.
    Determines the declared Nullability of the given parameter, consulting every NullabilityResolver found on the classpath before falling back to the built-in annotation check.
    resolve(Parameter parameter)
    Determines the declared Nullability of the given parameter.
  • Method Details

    • resolve

      Nullability resolve(Parameter parameter)
      Determines the declared Nullability of the given parameter.
      Parameters:
      parameter - the parameter to determine the nullability of
      Returns:
      the declared nullability, or Nullability.UNKNOWN when this resolver cannot tell
    • nullabilityOf

      static Nullability nullabilityOf(Parameter parameter)
      Determines the declared Nullability of the given parameter, consulting every NullabilityResolver found 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.UNKNOWN when no resolver could tell
    • isNullable

      static boolean isNullable(Parameter parameter)
      Indicates whether the given parameter is explicitly declared as accepting null.

      Note that a false result covers both an explicitly non-null parameter and one whose nullability could not be determined. Use nullabilityOf(Parameter) to tell those apart.

      Parameters:
      parameter - the parameter to inspect
      Returns:
      true if the parameter is explicitly declared as accepting null