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
ConfigExceptionfor circular references
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultConfigReferenceErrorHandler(@NotNull Logger logger) Creates a new handler with the given logger. -
Method Summary
Modifier and TypeMethodDescriptionvoidonCircularReference(@NotNull ConfigCircularReferenceContext context) Called when a circular reference is detected during resolution.@Nullable ObjectonReferenceNotFound(@NotNull ConfigReferenceNotFoundContext context) Called when a reference cannot be resolved because the target config, folder config, item, or path was not found.@Nullable ObjectonTypeMismatch(@NotNull ConfigTypeMismatchContext context) 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 anintfield).
-
Constructor Details
-
DefaultConfigReferenceErrorHandler
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:ConfigReferenceErrorHandlerCalled when a reference cannot be resolved because the target config, folder config, item, or path was not found.- Specified by:
onReferenceNotFoundin interfaceConfigReferenceErrorHandler- Parameters:
context- context information about the error- Returns:
- a fallback value to use (typically null), or throw an exception
-
onCircularReference
Description copied from interface:ConfigReferenceErrorHandlerCalled 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:
onCircularReferencein interfaceConfigReferenceErrorHandler- Parameters:
context- context information about the cycle
-
onTypeMismatch
@Nullable public @Nullable Object onTypeMismatch(@NotNull @NotNull ConfigTypeMismatchContext context) Description copied from interface:ConfigReferenceErrorHandlerCalled 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 anintfield).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:
onTypeMismatchin interfaceConfigReferenceErrorHandler- Parameters:
context- context information about the type mismatch- Returns:
- a fallback value to use (typically null), or throw an exception
-