junit-team/junit5 · error · CsvParsingException

Failed to parse CSV input configured via %s

Error message

Failed to parse CSV input configured via %s

What it means

Thrown by CsvArgumentsProvider.handleCsvException when CSV parsing fails for any reason other than a PreconditionViolationException. It first rethrows unrecoverable errors and PreconditionViolationException as-is, then wraps all remaining throwables in a CsvParsingException naming the source annotation. The annotation in the message identifies which @CsvSource/@CsvFileSource configured the input.

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 f070c699a0)

Solutions

  1. Inspect the wrapped cause for the precise parse error (line/column).
  2. Verify each CSV row has the correct number of columns for the test parameters.
  3. Check @CsvSource attributes: delimiter, quoteChar, emptyValue, nullValues, and column count.
  4. Escape quotes by doubling them and ensure no stray delimiters.

Example fix

// before
@CsvSource({
  "1, 'a",
  "2, b"
})

// after
@CsvSource({
  "1, 'a'",
  "2, 'b'"
})
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate CSV rows against the expected column count and types
String delimiter = ",";
int expectedCols = 3;
for (String row : csvRows) {
    String[] cols = row.split(delimiter, -1);
    if (cols.length != expectedCols)
        throw new IllegalArgumentException("Bad CSV row: " + row);
}

Try / catch

try {
    runParameterizedTest();
} catch (CsvParsingException e) {
    // e.getCause() holds the underlying parse error with line/column
    fail("CSV parse failure: " + e.getCause().getMessage());
}

Prevention

When it happens

Trigger: Malformed CSV rows, wrong delimiter, unescaped quotes, column count mismatch, or invalid number/boolean tokens while parsing arguments from @CsvSource. Any underlying parse Throwable that is not a PreconditionViolationException reaches the final throw.

Common situations: Typo in CSV literal (extra comma, missing quote). Mismatch between the number of CSV columns and the @ParameterizedTest parameter count. Wrong delimiter or empty-quote configuration on @CsvSource. Non-numeric value supplied for a numeric parameter.

Understand the failure class

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/3b340a43eaaae8d5. Report an issue: GitHub.