quarkusio/quarkus · error · RuntimeException

Using both 'format' and 'dateTimeFormatterProvider' is not a

Error message

Using both 'format' and 'dateTimeFormatterProvider' is not allowed when using '@DateFormat'

What it means

@DateFormat accepts either a built-in 'format' pattern or a 'dateTimeFormatterProvider' class supplying a custom DateTimeFormatter — never both, as that is ambiguous. When both attributes are set, deployment fails with this RuntimeException.

Source

Thrown at independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/ServerEndpointIndexer.java:627

            }

            AnnotationValue dateTimeFormatterProviderValue = dateFormatInstance.value("dateTimeFormatterProvider");
            if (dateTimeFormatterProviderValue != null) {
                dateTimeFormatterProviderClassName = dateTimeFormatterProviderValue.asClass().name().toString();
            }
        }

        if (INSTANT.equals(paramType)) {
            if (dateFormatInstance != null) {
                throw new RuntimeException(contextualizeErrorMessage(
                        "'java.time.Instant' types must not be annotated with '@DateFormat'",
                        currentMethodInfo));
            }
            return new InstantParamConverter.Supplier();
        }

        if ((format != null) && (dateTimeFormatterProviderClassName != null)) {
            throw new RuntimeException(contextualizeErrorMessage(
                    "Using both 'format' and 'dateTimeFormatterProvider' is not allowed when using '@DateFormat'",
                    currentMethodInfo));
        } else if ((format == null) && (dateTimeFormatterProviderClassName == null) && (dateFormatInstance != null)) {
            throw new RuntimeException(contextualizeErrorMessage(
                    "One of 'format' or 'dateTimeFormatterProvider' must be set when using '@DateFormat'", currentMethodInfo));
        }

        if (LOCAL_DATE.equals(paramType)) {
            return new LocalDateParamConverter.Supplier(format, dateTimeFormatterProviderClassName);
        } else if (LOCAL_DATE_TIME.equals(paramType)) {
            return new LocalDateTimeParamConverter.Supplier(format, dateTimeFormatterProviderClassName);
        } else if (LOCAL_TIME.equals(paramType)) {
            return new LocalTimeParamConverter.Supplier(format, dateTimeFormatterProviderClassName);
        } else if (OFFSET_DATE_TIME.equals(paramType)) {
            return new OffsetDateTimeParamConverter.Supplier(format, dateTimeFormatterProviderClassName);
        } else if (OFFSET_TIME.equals(paramType)) {
            return new OffsetTimeParamConverter.Supplier(format, dateTimeFormatterProviderClassName);
        } else if (ZONED_DATE_TIME.equals(paramType)) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Keep only one attribute: delete 'format' if using a provider, or delete 'dateTimeFormatterProvider' if using the pattern.
  2. Rely on the provider alone if it encapsulates the pattern.
  3. Rebuild and run a startup test — the error only surfaces at deployment.

Example fix

// before
@DateFormat(format = "yyyy-MM-dd", dateTimeFormatterProvider = AppDateFormatter.class)
@QueryParam("from")
LocalDate from;

// after
@DateFormat(dateTimeFormatterProvider = AppDateFormatter.class)
@QueryParam("from")
LocalDate from;
Defensive patterns

Strategy: validation

Validate before calling

DateFormat df = field.getAnnotation(DateFormat.class);
if (df != null && !df.format().isEmpty()
    && df.dateTimeFormatterProvider() != void.class && df.dateTimeFormatterProvider() != null) {
    throw new IllegalStateException("Use either format or dateTimeFormatterProvider, not both");
}

Prevention

When it happens

Trigger: @DateFormat(format = "yyyy-MM-dd", dateTimeFormatterProvider = MyProvider.class) on a temporal parameter (LocalDate, LocalDateTime, OffsetDateTime, etc.).

Common situations: Migrating from a pattern to a provider and forgetting to delete 'format'; copy-pasting annotated parameters and adding a second attribute.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/9f67f6a94793eb39. Report an issue: GitHub.