quarkusio/quarkus · error · IllegalArgumentException

Date instances are not supported by this class.

Error message

Date instances are not supported by this class.

What it means

RESTEasy Reactive's TypeConverter converts String values to target types for simple types only. Date (and subclasses like java.sql.Date/Timestamp) require parsing rules (formats, timezones) that this class deliberately does not handle, so getType() throws IllegalArgumentException when the target type is assignable from Date.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/TypeConverter.java:61

    /**
     * A generic method that returns the {@link String} as the specified Java type.
     *
     * @param <T> the type to return
     * @param source the string value to convert
     * @param targetType target type
     * @return the object instance
     */
    @SuppressWarnings(value = "unchecked")
    public static <T> T getType(final Class<T> targetType, final String source) {
        // just return that source if it's a String
        if (String.class.equals(targetType)) {
            return targetType.cast(source);
        }
        /*
         * Dates are too complicated for this class.
         */
        if (Date.class.isAssignableFrom(targetType)) {
            throw new IllegalArgumentException("Date instances are not supported by this class.");
        }
        if (Character.class.equals(targetType)) {
            if (source.length() == 0)
                return targetType.cast(new Character('\0'));
            return targetType.cast(new Character(source.charAt(0)));
        }
        if (char.class.equals(targetType)) {
            Character c = null;
            if (source.length() == 0)
                c = new Character('\0');
            else
                c = new Character(source.charAt(0));
            try {
                return (T) Character.class.getMethod("charValue").invoke(c);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use a dedicated date parser (DateTimeFormatter, SimpleDateFormat, or Jackson) for Date fields instead of TypeConverter
  2. Switch the field type to a supported type such as LocalDate/OffsetDateTime with a DateTimeFormatter
  3. Write a custom converter for the Date field and route around TypeConverter for it
  4. If you own the utility call site, pre-check Date.class.isAssignableFrom(targetType) and handle it before calling getType

Example fix

// before
Object v = TypeConverter.getType("2024-01-15", Date.class);
// after
LocalDate v = LocalDate.parse("2024-01-15", DateTimeFormatter.ISO_LOCAL_DATE);
Defensive patterns

Strategy: type-guard

Validate before calling

if (Date.class.isAssignableFrom(targetType)) {
    throw new IllegalArgumentException("Use DateTimeFormatter for Date targets, not TypeConverter");
}

Type guard

static boolean isUnsupportedDateType(Class<?> targetType) {
    return Date.class.isAssignableFrom(targetType);
}

Try / catch

try {
    value = TypeConverter.getType(source, targetType);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Date instances are not supported")) {
        value = parseDateWithFormatter(source);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling TypeConverter.getType(source, targetType) (or code paths using it, e.g., some config/bean population utilities) with targetType assignable from java.util.Date.

Common situations: Reflection-based population of DTOs that contain java.util.Date fields from string values; migrating code that previously used a different conversion utility that did support dates; passing Date subclasses (java.sql.Date, Timestamp) as conversion targets.

Related errors


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