{"id":"e32773995690f1ac","repo":"junit-team/junit5","slug":"failed-to-inject-parameter-value-into-field-fiel","errorCode":null,"errorMessage":"Failed to inject parameter value into field: <field>","messagePattern":"Failed to inject parameter value into field: <field>","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java","lineNumber":313,"sourceCode":"\t\t\t\t\t\tinvocationIndex, resolutionCache));\n\t\t}\n\t}\n\n\tprivate Stream<ParameterDeclaration> getAllParameterDeclarations() {\n\t\treturn Stream.concat(this.indexedParameterDeclarations.declarationsByIndex.values().stream(),\n\t\t\taggregatorParameters.stream());\n\t}\n\n\tprivate void setField(Object testInstance, FieldParameterDeclaration declaration, ExtensionContext extensionContext,\n\t\t\tEvaluatedArgumentSet arguments, int invocationIndex, ResolutionCache resolutionCache) {\n\n\t\tObject argument = resolutionCache.resolve(declaration,\n\t\t\t() -> resolve(declaration, extensionContext, arguments, invocationIndex, Optional.empty()));\n\t\ttry {\n\t\t\tdeclaration.getField().set(testInstance, argument);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new JUnitException(\"Failed to inject parameter value into field: \" + declaration.getField(), e);\n\t\t}\n\t}\n\n\tprivate @Nullable Object resolve(ResolvableParameterDeclaration parameterDeclaration,\n\t\t\tExtensionContext extensionContext, EvaluatedArgumentSet arguments, int invocationIndex,\n\t\t\tOptional<ParameterContext> parameterContext) {\n\t\tResolver resolver = getResolver(extensionContext, parameterDeclaration);\n\t\treturn parameterDeclaration.resolve(resolver, extensionContext, arguments, invocationIndex, parameterContext);\n\t}\n\n\tprivate Resolver getResolver(ExtensionContext extensionContext, ResolvableParameterDeclaration declaration) {\n\t\treturn this.resolvers.computeIfAbsent(declaration, __ -> this.aggregatorParameters.contains(declaration) //\n\t\t\t\t? createAggregator(declaration, extensionContext) //\n\t\t\t\t: createConverter(declaration, extensionContext));\n\t}\n\n\tprivate int toLogicalIndex(ParameterContext parameterContext) {\n\t\tint index = parameterContext.getIndex() - this.parameterIndexOffset;","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ResolverFacade.java#L295-L331","documentation":"Thrown by ResolverFacade.setField() when Field.set() fails during field injection for a @ParameterizedClass field annotated with @Parameter. After the argument is resolved and converted, JUnit reflectively sets it on the test instance; if this reflective write throws (IllegalAccessException, IllegalArgumentException, or a type mismatch after conversion), it is wrapped in this JUnitException.","triggerScenarios":"A @ParameterizedClass with a @Parameter field whose declared type is incompatible with the converted argument value at runtime. Despite the field being made accessible, Field.set() throws IllegalArgumentException if the argument type does not match the field type after conversion.","commonSituations":"Declaring @Parameter(0) on a field of type int but the CSV source provides a non-numeric string that was not properly converted. A custom @ConvertWith converter returns a type incompatible with the field. Security manager restrictions on reflection (rare in modern JVMs).","solutions":["Ensure the @Parameter field type matches what the argument source and converter produce","Add a @ConvertWith converter if the default converter cannot handle the source-to-field-type mapping","Check the nested exception (cause) for the exact Field.set() failure — IllegalArgumentException typically indicates a type mismatch","Verify the CSV/value source column aligns with the @Parameter index"],"exampleFix":"// before\n@ParameterizedClass\n@CsvSource(\"hello, 2\")\nclass MyTest {\n    @Parameter(0) int a; // 'hello' cannot convert to int\n    @Parameter(1) int b;\n}\n\n// after\n@ParameterizedClass\n@CsvSource(\"1, 2\")\nclass MyTest {\n    @Parameter(0) int a;\n    @Parameter(1) int b;\n}","handlingStrategy":"try-catch","validationCode":"// Ensure field types match argument source columns before running:\n// @Parameter(0) int a  <-> CSV column 0 must be numeric\n// Validate by checking the source data type vs field type:","typeGuard":null,"tryCatchPattern":"// This error occurs during test instance setup, not in user code.\n// Prevent by ensuring field types match converted argument types.\n// Check the nested cause for the exact Field.set failure.","preventionTips":["Ensure @Parameter field types are compatible with the source data and any converters","Do not declare @Parameter fields as incompatible types for the CSV/value source columns","Add @ConvertWith converters when the default converter cannot handle the source-to-field mapping","Check the nested exception cause for the specific IllegalArgumentException detail"],"tags":["parameterized-class","field-injection","type-mismatch","reflection","junit-jupiter-params"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}