Class DefaultConfigReferenceErrorHandler

java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.DefaultConfigReferenceErrorHandler
All Implemented Interfaces:
ConfigReferenceErrorHandler

public class DefaultConfigReferenceErrorHandler extends Object implements ConfigReferenceErrorHandler
Default implementation of ConfigReferenceErrorHandler.

This handler:

  • Logs warnings for missing references and type mismatches, returning null
  • Throws ConfigException for circular references
  • Constructor Details

    • DefaultConfigReferenceErrorHandler

      public DefaultConfigReferenceErrorHandler(@NotNull @NotNull Logger logger)
      Creates a new handler with the given logger.
      Parameters:
      logger - the logger to use for warnings
  • Method Details

    • onReferenceNotFound

      @Nullable public @Nullable Object onReferenceNotFound(@NotNull @NotNull ConfigReferenceNotFoundContext context)
      Description copied from interface: ConfigReferenceErrorHandler
      Called when a reference cannot be resolved because the target config, folder config, item, or path was not found.
      Specified by:
      onReferenceNotFound in interface ConfigReferenceErrorHandler
      Parameters:
      context - context information about the error
      Returns:
      a fallback value to use (typically null), or throw an exception
    • onCircularReference

      public void onCircularReference(@NotNull @NotNull ConfigCircularReferenceContext context)
      Description copied from interface: ConfigReferenceErrorHandler
      Called when a circular reference is detected during resolution.

      This method should typically throw an exception as circular references cannot be resolved. Returning normally is allowed but may lead to incomplete resolution.

      Specified by:
      onCircularReference in interface ConfigReferenceErrorHandler
      Parameters:
      context - context information about the cycle
    • onTypeMismatch

      @Nullable public @Nullable Object onTypeMismatch(@NotNull @NotNull ConfigTypeMismatchContext context)
      Description copied from interface: ConfigReferenceErrorHandler
      Called when a resolved reference value cannot be coerced into the scalar or primitive type expected by the target field (for example, a non-numeric resolved value bound to an int field).

      The returned value is used in place of the resolved value (typically null, which binds the field to its default); the binder will then bind/coerce that fallback as usual. Implementations may also throw to abort binding.

      Specified by:
      onTypeMismatch in interface ConfigReferenceErrorHandler
      Parameters:
      context - context information about the type mismatch
      Returns:
      a fallback value to use (typically null), or throw an exception