{"record":{"id":"80c9e5f3a773f0b0","repo":"junit-team/junit5","slug":"cannot-convert-to-s-s","errorCode":null,"errorMessage":"Cannot convert to %s: %s","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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/JavaTimeArgumentConverter.java#L49-L75","documentation":"Thrown by JavaTimeArgumentConverter when the requested target type is not one of the supported java.time temporal types registered in TEMPORAL_QUERIES. The converter looks up a TemporalQuery by target class; if no entry exists it cannot know how to parse the input string into that type. This is a hard precondition failure of @JavaTimeConversionPattern.","triggerScenarios":"Annotating a @ParameterizedTest parameter with @JavaTimeConversionPattern and declaring a target type that is not in the TEMPORAL_QUERIES map (e.g. java.util.Date, java.sql.Timestamp, or a custom temporal class). The converter reaches the `if (temporalQuery == null)` branch and throws.","commonSituations":"Migrating parameterized tests from older date types to java.time and forgetting that only LocalDate, LocalTime, LocalDateTime, YearMonth, etc. are supported. Declaring a legacy Date/Calendar parameter expecting the converter to handle it. Typo or wrong import causing the resolved target class to differ from the intended java.time type.","solutions":["Change the parameter type to a supported java.time type such as LocalDate, LocalTime, LocalDateTime, Instant, Year, YearMonth, MonthDay, or OffsetDateTime.","If you must use a non-temporal type, write a custom ArgumentConverter via @ConvertWith instead of @JavaTimeConversionPattern.","Verify the import of the parameter type is from java.time and not java.util/java.sql.","Check the conversion pattern string in @JavaTimeConversionPattern matches the input data format."],"exampleFix":"// before\n@ParameterizedTest\n@CsvSource(\"2024-01-01\")\nvoid test(@JavaTimeConversionPattern(\"yyyy-MM-dd\") java.util.Date date) { }\n\n// after\n@ParameterizedTest\n@CsvSource(\"2024-01-01\")\nvoid test(@JavaTimeConversionPattern(\"yyyy-MM-dd\") LocalDate date) { }","handlingStrategy":"validation","validationCode":"// Before binding the parameter, confirm the target type is a supported temporal type\nprivate static final Set<Class<?>> SUPPORTED = Set.of(\n    LocalDate.class, LocalTime.class, LocalDateTime.class,\n    Year.class, YearMonth.class, MonthDay.class, Instant.class,\n    OffsetDateTime.class, OffsetTime.class, ZonedDateTime.class);\n\nif (!SUPPORTED.contains(targetType)) {\n    throw new IllegalArgumentException(\"Unsupported temporal type: \" + targetType);\n}","typeGuard":"static boolean isSupportedJavaTimeType(Class<?> c) {\n    return c == LocalDate.class || c == LocalTime.class || c == LocalDateTime.class\n        || c == Year.class || c == YearMonth.class || c == MonthDay.class\n        || c == Instant.class || c == OffsetDateTime.class || c == OffsetTime.class\n        || c == ZonedDateTime.class;\n}","tryCatchPattern":null,"preventionTips":["Restrict @JavaTimeConversionPattern parameters to documented java.time types.","Keep parameter imports consistent (java.time.*) when using this annotation.","Write a custom ArgumentConverter for non-temporal types instead of forcing JavaTimeArgumentConverter."],"tags":["junit-jupiter","parameterized-test","argument-conversion","java-time"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}