{"id":"b6c21f1deaf79707","repo":"junit-team/junit5","slug":"cannot-convert-to-targetclass-getname-inpu","errorCode":null,"errorMessage":"Cannot convert to ${targetClass.getName()}: ${input}","messagePattern":"Cannot convert to (.+?): (.+?)","errorType":"exception","errorClass":"ArgumentConversionException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/JavaTimeArgumentConverter.java","lineNumber":67,"sourceCode":"\t\tqueries.put(YearMonth.class, YearMonth::from);\n\t\tqueries.put(ZonedDateTime.class, ZonedDateTime::from);\n\t\tTEMPORAL_QUERIES = Collections.unmodifiableMap(queries);\n\t}\n\n\t@Override\n\tprotected @Nullable Object convert(@Nullable Object input, Class<?> targetClass,\n\t\t\tJavaTimeConversionPattern annotation) {\n\n\t\tif (input == null) {\n\t\t\tif (annotation.nullable()) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow new ArgumentConversionException(\n\t\t\t\t\"Cannot convert null to \" + targetClass.getName() + \"; consider setting 'nullable = true'\");\n\t\t}\n\t\tTemporalQuery<?> temporalQuery = TEMPORAL_QUERIES.get(targetClass);\n\t\tif (temporalQuery == null) {\n\t\t\tthrow new ArgumentConversionException(\"Cannot convert to \" + targetClass.getName() + \": \" + input);\n\t\t}\n\t\tString pattern = annotation.value();\n\t\tDateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);\n\t\treturn formatter.parse(input.toString(), temporalQuery);\n\t}\n\n}\n","sourceCodeStart":49,"sourceCodeEnd":75,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/JavaTimeArgumentConverter.java#L49-L75","documentation":"Thrown by JavaTimeArgumentConverter.convert() when the target parameter type is not one of the supported temporal types (ChronoLocalDate, ChronoLocalDateTime, ChronoZonedDateTime, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, Year, YearMonth, ZonedDateTime). The TEMPORAL_QUERIES map does not contain an entry for the requested type.","triggerScenarios":"A @ParameterizedTest parameter annotated with @JavaTimeConversionPattern whose type is not in the supported set — e.g., java.util.Date, java.time.Duration, java.time.Instant, java.time.Period, or a custom temporal class. The converter only supports parse via DateTimeFormatter into the listed TemporalQuery types.","commonSituations":"Using @JavaTimeConversionPattern on a parameter of type Instant, Duration, or Period (which are not in the supported map). Annotating a java.util.Date or java.sql.Date parameter with @JavaTimeConversionPattern. Confusing which java.time types are supported by this specific converter.","solutions":["Use a supported target type: LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, Year, YearMonth, ZonedDateTime (or their Chrono* equivalents)","For unsupported types like Instant or Duration, write a custom @ConvertWith converter instead of @JavaTimeConversionPattern","For java.util.Date, use a custom ArgumentConverter or switch to a supported java.time type","Remove @JavaTimeConversionPattern and rely on the default converter which may handle some types via ConversionSupport"],"exampleFix":"// before\n@ParameterizedTest\n@CsvSource(\"2024-01-15T10:00:00Z\")\nvoid test(@JavaTimeConversionPattern(\"yyyy-MM-dd'T'HH:mm:ss'Z'\") Instant date) { }\n\n// after (use a supported type or a custom converter)\n@ParameterizedTest\n@CsvSource(\"2024-01-15T10:00:00Z\")\nvoid test(@JavaTimeConversionPattern(\"yyyy-MM-dd'T'HH:mm:ss'Z'\") OffsetDateTime date) { }","handlingStrategy":"validation","validationCode":"// Validate that the target type is supported by JavaTimeArgumentConverter:\nstatic final Set<Class<?>> SUPPORTED = Set.of(\n    LocalDate.class, LocalDateTime.class, LocalTime.class,\n    OffsetDateTime.class, OffsetTime.class, Year.class,\n    YearMonth.class, ZonedDateTime.class,\n    ChronoLocalDate.class, ChronoLocalDateTime.class, ChronoZonedDateTime.class);\nif (!SUPPORTED.contains(targetType)) {\n    throw new IllegalStateException(\n        targetType + \" is not supported by @JavaTimeConversionPattern; use a custom converter\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use @JavaTimeConversionPattern with supported types: LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, Year, YearMonth, ZonedDateTime","For Instant, Duration, Period, or java.util.Date, write a custom @ConvertWith converter instead","Check the TEMPORAL_QUERIES map in JavaTimeArgumentConverter source for the exact supported set"],"tags":["argument-converter","java-time","unsupported-type","parameterized-test","junit-jupiter-params"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}