junit-team/junit5 · error · CsvParsingException
Failed to parse CSV input configured via ${annotation}
Error message
Failed to parse CSV input configured via ${annotation} What it means
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.
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvArgumentsProvider.java:144
return ((NamedCsvRecord) record).getHeader();
}
@SuppressWarnings({ "ReferenceEquality", "StringEquality" })
private static @Nullable String resolveNullMarker(String record) {
return record == CsvReaderFactory.DefaultFieldModifier.NULL_MARKER ? null : record;
}
/**
* @return this method always throws an exception and therefore never
* returns anything; the return type is merely present to allow this
* method to be supplied as the operand in a {@code throw} statement
*/
static RuntimeException handleCsvException(Throwable throwable, Annotation annotation) {
UnrecoverableExceptions.rethrowIfUnrecoverable(throwable);
if (throwable instanceof PreconditionViolationException exception) {
throw exception;
}
throw new CsvParsingException("Failed to parse CSV input configured via " + annotation, throwable);
}
}
View on GitHub (pinned to 956246301e)
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.
Example fix
// before
@ParameterizedTest
@CsvSource({
"name,age",
"Alice,30,extra" // column count differs from header
})
void test(String name, int age) { }
// after
@ParameterizedTest
@CsvSource({
"name,age",
"Alice,30"
})
void test(String name, int age) { } Defensive patterns
Strategy: validation
Validate before calling
// Validate every @CsvSource row before declaring the test.
String[][] rows = { {"name","age"}, {"Alice,30"} };
int cols = rows[0].length;
for (String[] r : rows) {
// simple sanity: same field count when split on the delimiter
long count = r[0].chars().filter(c -> c == ',').count() + 1;
if (count != cols) throw new IllegalArgumentException("inconsistent CSV row: " + r[0]);
} Try / catch
try {
// execute parameterized test
} catch (CsvParsingException e) {
// log the annotation + cause, then correct the @CsvSource value/textBlock
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- %s cannot convert to type [%s]. Only target type [%s] is sup
- The charset supplied in ${csvFileSource} is invalid
- File [${path}] could not be read
- @EmptySource cannot provide an empty argument %s: [%s] is no
- Pattern compilation failed for a regular expression supplied
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/d0e11e7fcd612b30.json.
Report an issue: GitHub.