stanfordnlp/CoreNLP · error · IllegalArgumentException
Too many columns: / (offset: )
Error message
Too many columns: <columnI>/<numColumns> (offset: <offset>)
What it means
Thrown by IOUtils' CSV/TSV line parser (csvStringToColumns-style readers) when a line contains MORE comma-separated fields than the declared number of columns. While parsing a non-quoted line, encountering a comma that would advance columnI past numColumns-1 raises this IllegalArgumentException with column counts and the character offset in the input.
Solutions
- Increase the numColumns argument to match the actual maximum number of comma-separated fields per row.
- Quote fields that contain literal commas in the source data (standard CSV quoting) so the parser treats them as part of one field.
- Pre-validate the file: count fields per line (outside quotes) and reject/report offending lines before calling the parser.
- If the delimiter is not a comma, use the correct parsing method/separator instead.
Example fix
// before
List<String[]> cols = IOUtils.csvStringToColumns(csvText, 3);
// after
int maxFields = csvText.lines().mapToInt(l -> l.split(",(?=(?:[^"]*[^"]*")*[^"]*$)").length).max().orElse(0);
List<String[]> cols = IOUtils.csvStringToColumns(csvText, maxFields); Defensive patterns
Strategy: validation
Validate before calling
int expectedCols = numColumns;
int lineNo = 0;
for (String line : csvText.split("\n")) {
lineNo++;
if (countFields(line) > expectedCols)
throw new IllegalArgumentException("Line " + lineNo + " has too many fields (unquoted comma?)");
}
static int countFields(String line) {
int n = 1; boolean inQ = false;
for (char c : line.toCharArray()) {
if (c == '"') inQ = !inQ;
else if (c == ',' && !inQ) n++;
}
return n;
} Try / catch
try {
List<String[]> cols = IOUtils.csvStringToColumns(csvText, numColumns);
} catch (IllegalArgumentException e) {
// e.getMessage() contains columnI/numColumns and offset; report line/offset to data owner
throw new DataFormatException("Bad CSV row: " + e.getMessage());
} Prevention
- Quote any field containing a comma in source data.
- Derive numColumns from the data (max fields per row) instead of hard-coding.
- Keep a schema check in CI for pipeline inputs.
When it happens
Trigger: Calling the CSV reader (e.g. slurpFileAsColumns / csvStringToColumns variants) with a numColumns argument smaller than the actual field count of some row: unquoted commas inside field values, a header declaring fewer columns than data rows, or a wrong numColumns constant in the caller.
Common situations: CSV data exported from Excel with commas inside text that was not quote-escaped; a pipeline expects 3 columns but source data gained a 4th; parsing a TSV file while passing ',' as separator mismatch; hard-coded numColumns not updated after schema change.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Too few columns: / (offset: )
- Cannot parse Trilean from string: " + value
- Bad data format:
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b6e1a1ef8097ffac.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:1451
//--Read
for(int offset=0; offset<csvContents.length; offset++){
if(nextIsEscaped){
buffer[columnI].append(csvContents[offset]);
nextIsEscaped = false;
} else {
switch(csvContents[offset]){
case '"':
//(case: quotes)
inQuotes = !inQuotes;
break;
case ',':
//(case: field separator)
if(inQuotes){
buffer[columnI].append(',');
} else {
columnI += 1;
if(columnI >= numColumns){
throw new IllegalArgumentException("Too many columns: "+columnI+"/"+numColumns+" (offset: " + offset + ")");
}
buffer[columnI] = new StringBuilder();
}
break;
case '\n':
//(case: newline)
if(inQuotes){
buffer[columnI].append('\n');
} else {
//((error checks))
if(columnI != numColumns-1){
throw new IllegalArgumentException("Too few columns: "+columnI+"/"+numColumns+" (offset: " + offset + ")");
}
//((create line))
String[] rtn = new String[buffer.length];
for(int i=0; i<buffer.length; i++){ rtn[i] = buffer[i].toString(); }
lines.add(rtn);
//((update state))View on GitHub (pinned to 1b7edd19c4)