{"id":"f789d66008eb4176","repo":"junit-team/junit5","slug":"parameterresolver-s-resolved-a-value-of-type","errorCode":null,"errorMessage":"ParameterResolver [%s] resolved a value of type [%s] for parameter [%s] in %s [%s], but a value assignment compatible with [%s] is required.","messagePattern":"ParameterResolver \\[(.+?)\\] resolved a value of type \\[(.+?)\\] for parameter \\[(.+?)\\] in (.+?) \\[(.+?)\\], but a value assignment compatible with \\[(.+?)\\] is required\\.","errorType":"exception","errorClass":"ParameterResolutionException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/ParameterResolutionUtils.java","lineNumber":201,"sourceCode":"\t\t// Note: null is permissible as a resolved value but only for non-primitive types.\n\t\tif (!isAssignableTo(value, type)) {\n\t\t\tString message;\n\t\t\tif (value == null && type.isPrimitive()) {\n\t\t\t\tmessage = \"\"\"\n\t\t\t\t\t\tParameterResolver [%s] resolved a null value for parameter [%s] \\\n\t\t\t\t\t\tin %s [%s], but a primitive of type [%s] is required.\"\"\".formatted(\n\t\t\t\t\tresolver.getClass().getName(), parameter, asLabel(executable), executable.toGenericString(),\n\t\t\t\t\ttype.getName());\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmessage = \"\"\"\n\t\t\t\t\t\tParameterResolver [%s] resolved a value of type [%s] for parameter [%s] \\\n\t\t\t\t\t\tin %s [%s], but a value assignment compatible with [%s] is required.\"\"\".formatted(\n\t\t\t\t\tresolver.getClass().getName(), (value != null ? value.getClass().getTypeName() : null), parameter,\n\t\t\t\t\tasLabel(executable), executable.toGenericString(), type.getTypeName());\n\t\t\t}\n\n\t\t\tthrow new ParameterResolutionException(message);\n\t\t}\n\t}\n\n\tprivate static String asLabel(Executable executable) {\n\t\treturn executable instanceof Constructor ? \"constructor\" : \"method\";\n\t}\n\n\tprivate ParameterResolutionUtils() {\n\t}\n\n}\n","sourceCodeStart":183,"sourceCodeEnd":213,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/ParameterResolutionUtils.java#L183-L213","documentation":"Thrown by ParameterResolutionUtils.validateResolvedType() when a ParameterResolver returns a non-null value whose type is not assignment-compatible with the declared parameter type (and the parameter is not a primitive). The message names the resolver, the actual value type, the parameter, the executable, and the required type.","triggerScenarios":"A ParameterResolver.resolveParameter() returns an object whose class is not assignable to the parameter's declared type — e.g. returning a String for a Path parameter, an Integer for a List parameter, or a custom argument converter producing the wrong type.","commonSituations":"A custom argument converter/resolver returning the wrong type after a refactor; @CsvSource parsing a column as a String when the parameter expects a typed value and no ArgumentConverter is registered; a resolver that returns a raw type incompatible with a generic parameter under strict type checks.","solutions":["Make the resolver return a value whose type matches (or is a subtype of) the declared parameter type.","Register/fix an ArgumentConverter (via @ConvertWith) so @CsvSource/@EnumSource data converts to the parameter type.","Inspect the message — it states both the actual type and the required type — and align them.","For generic/boxing mismatches, narrow the parameter type or wrap the value appropriately."],"exampleFix":"// before\n@ParameterizedTest\n@CsvSource({ \"1,2\" })\nvoid test(Path p) { ... } // String \"1,2\" not assignable to Path\n\n// after\n@ParameterizedTest\n@CsvSource({ \"1,2\" })\nvoid test(String s) { ... } // matching type","handlingStrategy":"type-guard","validationCode":"// Validate resolved value is assignable before relying on the test\nObject value = resolver.resolveParameter(pc, ctx);\nif (value != null && !pc.getParameter().getType().isAssignableFrom(value.getClass())) {\n    throw new IllegalStateException(\"Type mismatch: \" + value.getClass() + \" vs \" + pc.getParameter().getType());\n}","typeGuard":"static boolean isAssignmentCompatible(Object value, Parameter p) {\n    return value == null || p.getType().isAssignableFrom(value.getClass());\n}","tryCatchPattern":null,"preventionTips":["Register an @ConvertWith ArgumentConverter for @CsvSource/@EnumSource columns that need type conversion.","Keep resolver return types aligned with declared parameter types after refactors.","Write a quick unit test asserting the resolver returns the expected type."],"tags":["junit-jupiter","parameter-resolution","type-mismatch","argument-conversion"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}