{"id":"d0e11e7fcd612b30","repo":"junit-team/junit5","slug":"failed-to-parse-csv-input-configured-via-annotat","errorCode":null,"errorMessage":"Failed to parse CSV input configured via ${annotation}","messagePattern":"Failed to parse CSV input configured via (.+?)","errorType":"exception","errorClass":"CsvParsingException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java","lineNumber":144,"sourceCode":"\t\treturn ((NamedCsvRecord) record).getHeader();\n\t}\n\n\t@SuppressWarnings({ \"ReferenceEquality\", \"StringEquality\" })\n\tprivate static @Nullable String resolveNullMarker(String record) {\n\t\treturn record == CsvReaderFactory.DefaultFieldModifier.NULL_MARKER ? null : record;\n\t}\n\n\t/**\n\t * @return this method always throws an exception and therefore never\n\t * returns anything; the return type is merely present to allow this\n\t * method to be supplied as the operand in a {@code throw} statement\n\t */\n\tstatic RuntimeException handleCsvException(Throwable throwable, Annotation annotation) {\n\t\tUnrecoverableExceptions.rethrowIfUnrecoverable(throwable);\n\t\tif (throwable instanceof PreconditionViolationException exception) {\n\t\t\tthrow exception;\n\t\t}\n\t\tthrow new CsvParsingException(\"Failed to parse CSV input configured via \" + annotation, throwable);\n\t}\n\n}\n","sourceCodeStart":126,"sourceCodeEnd":148,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java#L126-L148","documentation":"CsvArgumentsProvider.handleCsvException wraps any non-PreconditionViolation throwable raised by the fastcsv reader into a CsvParsingException with this message (it prints the source annotation). It indicates the CSV content declared via @CsvSource could not be parsed under the configured delimiter, quote, and record-separator rules.","triggerScenarios":"Malformed @CsvSource value or textBlock: a quoted field missing its closing quote, a record whose column count diverges from the others, a stray delimiter, or an incompatible CsvReaderConfiguration.","commonSituations":"Pasting tab-separated data into a comma-separated @CsvSource; smart quotes / non-breaking spaces copied from a doc; inconsistent column counts across rows; wrong delimiter or quoteChar attribute.","solutions":["Make every record have the same number of columns as the parameter list.","Wrap any field that contains the delimiter in the configured quote character.","Set delimiter / quoteChar / emptyValue / nullValue explicitly on @CsvSource to match the data.","Normalize quotes and strip BOM / non-breaking spaces from the source.","Switch to the textBlock form for multi-line CSV to make structure visible."],"exampleFix":"// before\n@ParameterizedTest\n@CsvSource({\n    \"name,age\",\n    \"Alice,30,extra\"   // column count differs from header\n})\nvoid test(String name, int age) { }\n\n// after\n@ParameterizedTest\n@CsvSource({\n    \"name,age\",\n    \"Alice,30\"\n})\nvoid test(String name, int age) { }","handlingStrategy":"validation","validationCode":"// Validate every @CsvSource row before declaring the test.\nString[][] rows = { {\"name\",\"age\"}, {\"Alice,30\"} };\nint cols = rows[0].length;\nfor (String[] r : rows) {\n    // simple sanity: same field count when split on the delimiter\n    long count = r[0].chars().filter(c -> c == ',').count() + 1;\n    if (count != cols) throw new IllegalArgumentException(\"inconsistent CSV row: \" + r[0]);\n}","typeGuard":null,"tryCatchPattern":"try {\n    // execute parameterized test\n} catch (CsvParsingException e) {\n    // log the annotation + cause, then correct the @CsvSource value/textBlock\n}","preventionTips":["Run the CSV through a real CSV parser (e.g. fastcsv) in a scratch test before declaring @CsvSource.","Quote every field that may contain the delimiter.","Prefer the textBlock form so column alignment is visually obvious.","Normalize quotes and strip BOM / non-breaking spaces from pasted CSV."],"tags":["junit","jupiter-params","csv","parameterized-test","parsing"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}