{"record":{"id":"8ba770cde1658f04","repo":"junit-team/junit5","slug":"no-built-in-converter-for-source-type-java-lang-st","errorCode":null,"errorMessage":"No built-in converter for source type java.lang.String and target type %s","messagePattern":"No built-in converter for source type java\\.lang\\.String and target type (.+?)","errorType":"exception","errorClass":"ConversionException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/ConversionSupport.java","lineNumber":140,"sourceCode":"\t\t\tcandidate -> candidate.canConvertTo(targetTypeToUse)).findFirst();\n\t\tif (converter.isPresent()) {\n\t\t\ttry {\n\t\t\t\tClassLoader classLoaderToUse = classLoader != null ? classLoader\n\t\t\t\t\t\t: ClassLoaderUtils.getDefaultClassLoader();\n\t\t\t\treturn (T) converter.get().convert(source, targetTypeToUse, classLoaderToUse);\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t\tif (ex instanceof ConversionException conversionException) {\n\t\t\t\t\t// simply rethrow it\n\t\t\t\t\tthrow conversionException;\n\t\t\t\t}\n\t\t\t\t// else\n\t\t\t\tthrow new ConversionException(\n\t\t\t\t\t\"Failed to convert String \\\"%s\\\" to type %s\".formatted(source, targetType.getTypeName()), ex);\n\t\t\t}\n\t\t}\n\n\t\tthrow new ConversionException(\n\t\t\t\"No built-in converter for source type java.lang.String and target type \" + targetType.getTypeName());\n\t}\n\n\tprivate static Class<?> toWrapperType(Class<?> targetType) {\n\t\tClass<?> wrapperType = getWrapperType(targetType);\n\t\treturn wrapperType != null ? wrapperType : targetType;\n\t}\n\n}\n","sourceCodeStart":122,"sourceCodeEnd":150,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/ConversionSupport.java#L122-L150","documentation":"Thrown when no registered StringToObjectConverter (including the convention-based FallbackStringToObjectConverter) accepts the target type. Reachable when the type is not a primitive/wrapper, enum, date-time, common java type, or Class, AND it has no single non-private static factory method or constructor accepting a String/CharSequence. Arrays, collections, and maps always fall through to this path.","triggerScenarios":"ConversionSupport.convert(\"...\", MyType.class, loader) where MyType has only a multi-arg constructor, only private factories, or multiple overloaded factories (ambiguous -> ignored by the search algorithm). Also convert to int[]/List/Map which JUnit cannot build from a single string.","commonSituations":"Trying to turn a CSV cell into a value object with no valueOf(String)/fromString(String)/<init>(String); targeting array/Collection/Map types; record types whose only constructor takes multiple components.","solutions":["Add a single non-private static factory method (e.g. public static MyType valueOf(String)) or a single-arg String constructor to the target type","Provide a custom ArgumentConverter via @ConvertWith on the parameter","Switch the parameter to a supported type (String, primitive, ...) and construct the object inside the test body","Use @AggregateWith with a custom ArgumentAggregator for multi-field types"],"exampleFix":"// before\n@ParameterizedTest\n@ValueSource(strings = \"1,2\")\nvoid test(Pair p) { ... }\n\n// after\nclass Pair {\n  final int a, b;\n  Pair(int a, int b) { this.a = a; this.b = b; }\n  public static Pair valueOf(String s) {\n    String[] parts = s.split(\",\");\n    return new Pair(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));\n  }\n}\n@ParameterizedTest\n@ValueSource(strings = \"1,2\")\nvoid test(Pair p) { ... }","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return ConversionSupport.convert(source, targetType, classLoader);\n} catch (ConversionException e) {\n    if (e.getMessage().contains(\"No built-in converter\")) {\n        // fall back to a custom converter or fail with a clearer message\n    }\n    throw e;\n}","preventionTips":["Add a public static valueOf(String) factory to any type used as a parameterized-test argument","Use @ConvertWith for types you cannot modify","Remember arrays, collections, and maps are not supported - use @AggregateWith"],"tags":["conversion","argument-conversion","parameterized-test"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}