junit-team/junit5 · error · ArgumentConversionException
Cannot convert to ${targetClass.getName()}: ${input}
Error message
Cannot convert to ${targetClass.getName()}: ${input} What it means
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.
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/JavaTimeArgumentConverter.java:67
queries.put(YearMonth.class, YearMonth::from);
queries.put(ZonedDateTime.class, ZonedDateTime::from);
TEMPORAL_QUERIES = Collections.unmodifiableMap(queries);
}
@Override
protected @Nullable Object convert(@Nullable Object input, Class<?> targetClass,
JavaTimeConversionPattern annotation) {
if (input == null) {
if (annotation.nullable()) {
return null;
}
throw new ArgumentConversionException(
"Cannot convert null to " + targetClass.getName() + "; consider setting 'nullable = true'");
}
TemporalQuery<?> temporalQuery = TEMPORAL_QUERIES.get(targetClass);
if (temporalQuery == null) {
throw new ArgumentConversionException("Cannot convert to " + targetClass.getName() + ": " + input);
}
String pattern = annotation.value();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return formatter.parse(input.toString(), temporalQuery);
}
}
View on GitHub (pinned to 956246301e)
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
Example fix
// before
@ParameterizedTest
@CsvSource("2024-01-15T10:00:00Z")
void test(@JavaTimeConversionPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") Instant date) { }
// after (use a supported type or a custom converter)
@ParameterizedTest
@CsvSource("2024-01-15T10:00:00Z")
void test(@JavaTimeConversionPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") OffsetDateTime date) { } Defensive patterns
Strategy: validation
Validate before calling
// Validate that the target type is supported by JavaTimeArgumentConverter:
static final Set<Class<?>> SUPPORTED = Set.of(
LocalDate.class, LocalDateTime.class, LocalTime.class,
OffsetDateTime.class, OffsetTime.class, Year.class,
YearMonth.class, ZonedDateTime.class,
ChronoLocalDate.class, ChronoLocalDateTime.class, ChronoZonedDateTime.class);
if (!SUPPORTED.contains(targetType)) {
throw new IllegalStateException(
targetType + " is not supported by @JavaTimeConversionPattern; use a custom converter");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot convert null to ${targetClass.getName()}; consider se
- Cannot convert null to primitive value of type ${targetType.
- No built-in converter for source type %s and target type %s
- %s cannot convert objects of type [%s]. Only source objects
- Unsupported argument count validation mode: <mode>
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/b6c21f1deaf79707.json.
Report an issue: GitHub.