{"record":{"id":"a1878810f2ee7c4a","repo":"quarkusio/quarkus","slug":"date-instances-are-not-supported-by-this-class","errorCode":null,"errorMessage":"Date instances are not supported by this class.","messagePattern":"Date instances are not supported by this class\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/TypeConverter.java","lineNumber":61,"sourceCode":"    /**\n     * A generic method that returns the {@link String} as the specified Java type.\n     *\n     * @param <T> the type to return\n     * @param source the string value to convert\n     * @param targetType target type\n     * @return the object instance\n     */\n    @SuppressWarnings(value = \"unchecked\")\n    public static <T> T getType(final Class<T> targetType, final String source) {\n        // just return that source if it's a String\n        if (String.class.equals(targetType)) {\n            return targetType.cast(source);\n        }\n        /*\n         * Dates are too complicated for this class.\n         */\n        if (Date.class.isAssignableFrom(targetType)) {\n            throw new IllegalArgumentException(\"Date instances are not supported by this class.\");\n        }\n        if (Character.class.equals(targetType)) {\n            if (source.length() == 0)\n                return targetType.cast(new Character('\\0'));\n            return targetType.cast(new Character(source.charAt(0)));\n        }\n        if (char.class.equals(targetType)) {\n            Character c = null;\n            if (source.length() == 0)\n                c = new Character('\\0');\n            else\n                c = new Character(source.charAt(0));\n            try {\n                return (T) Character.class.getMethod(\"charValue\").invoke(c);\n            } catch (IllegalAccessException e) {\n                throw new RuntimeException(e);\n            } catch (InvocationTargetException e) {\n                throw new RuntimeException(e);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/TypeConverter.java#L43-L79","documentation":"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.","triggerScenarios":"Calling TypeConverter.getType(source, targetType) (or code paths using it, e.g., some config/bean population utilities) with targetType assignable from java.util.Date.","commonSituations":"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.","solutions":["Use a dedicated date parser (DateTimeFormatter, SimpleDateFormat, or Jackson) for Date fields instead of TypeConverter","Switch the field type to a supported type such as LocalDate/OffsetDateTime with a DateTimeFormatter","Write a custom converter for the Date field and route around TypeConverter for it","If you own the utility call site, pre-check Date.class.isAssignableFrom(targetType) and handle it before calling getType"],"exampleFix":"// before\nObject v = TypeConverter.getType(\"2024-01-15\", Date.class);\n// after\nLocalDate v = LocalDate.parse(\"2024-01-15\", DateTimeFormatter.ISO_LOCAL_DATE);","handlingStrategy":"type-guard","validationCode":"if (Date.class.isAssignableFrom(targetType)) {\n    throw new IllegalArgumentException(\"Use DateTimeFormatter for Date targets, not TypeConverter\");\n}","typeGuard":"static boolean isUnsupportedDateType(Class<?> targetType) {\n    return Date.class.isAssignableFrom(targetType);\n}","tryCatchPattern":"try {\n    value = TypeConverter.getType(source, targetType);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Date instances are not supported\")) {\n        value = parseDateWithFormatter(source);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check Date.class.isAssignableFrom(targetType) before invoking TypeConverter","Model date fields as LocalDate/OffsetDateTime instead of java.util.Date","Use a real date parser (DateTimeFormatter) for any Date-typed input","When populating beans reflectively, special-case date fields before generic conversion"],"tags":["type-conversion","reflection","date","unsupported-operation"],"backgroundTag":"unsupported-type-conversion","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}