Annotation Interface Range


@Target(FIELD) @Retention(RUNTIME) public @interface Range
Validates that a numeric config value falls within the specified range. If the value is out of range, the module refuses to load naming the field, the actual value, and the violated bounds - the config file is never rewritten (D-01). On a reload the reload is refused instead and the running values are kept.

Since 6.3.0 (#625) the value must satisfy min <= value && value <= max, compared as a double: NaN (.nan in YAML) is out of every range, and positive or negative infinity (.inf, -.inf) is out of range unless the bound on that side is itself that infinity, for example max = Double.POSITIVE_INFINITY.

@Range checks numbers only: a primitive number or a Number such as Integer or BigDecimal.

On a value type it cannot check, the module is refused at load, before the file is read, naming the field and the annotation (since 6.3.0, #631; maintainer decision of 2026-10-06). So is this annotation on a field of a config class that is not a @ConfigEntry setting.

It takes effect only on a field that is itself a @ConfigEntry setting of a config class, judged by that field's declared type. A declared type that can hold a value the annotation checks - Object, Serializable, Comparable, CharSequence, Number or another supertype of a checked kind - is accepted, and the value bound at load is checked; only a type that can never hold a checkable value is a declaration error. A bound value of a kind the annotation cannot read (text under @Range, a number under @Pattern) is a violation like any other: the module is refused at load, and a reload is refused with the running values kept. On a field of a value type, a nested class or anything a converter produces it is never checked and not reported (maintainer decision of 2026-10-06): validate such fields in the module's converter.

See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    double
    Maximum allowed value (inclusive).
    double
    Minimum allowed value (inclusive).
  • Element Details

    • min

      double min
      Minimum allowed value (inclusive). Default: -Double.MAX_VALUE
      Default:
      -1.7976931348623157E308
    • max

      double max
      Maximum allowed value (inclusive). Default: Double.MAX_VALUE
      Default:
      1.7976931348623157E308