{"record":{"id":"57763300723cef40","repo":"stanfordnlp/CoreNLP","slug":"too-few-columns-columni-numcolumns-offset","errorCode":null,"errorMessage":"Too few columns: <columnI>/<numColumns> (offset: <offset>)","messagePattern":"Too few columns: <columnI>/<numColumns> \\(offset: <offset>\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":1463,"sourceCode":"            //(case: field separator)\n            if(inQuotes){\n              buffer[columnI].append(',');\n            } else {\n              columnI += 1;\n              if(columnI >= numColumns){\n                throw new IllegalArgumentException(\"Too many columns: \"+columnI+\"/\"+numColumns+\" (offset: \" + offset + \")\");\n              }\n              buffer[columnI] = new StringBuilder();\n            }\n            break;\n          case '\\n':\n            //(case: newline)\n            if(inQuotes){\n              buffer[columnI].append('\\n');\n            } else {\n              //((error checks))\n              if(columnI != numColumns-1){\n                throw new IllegalArgumentException(\"Too few columns: \"+columnI+\"/\"+numColumns+\" (offset: \" + offset + \")\");\n              }\n              //((create line))\n              String[] rtn = new String[buffer.length];\n              for(int i=0; i<buffer.length; i++){ rtn[i] = buffer[i].toString(); }\n              lines.add(rtn);\n              //((update state))\n              columnI = 0;\n              buffer[columnI] = new StringBuilder();\n            }\n            break;\n          case '\\\\':\n            nextIsEscaped = true;\n            break;\n          default:\n            buffer[columnI].append(csvContents[offset]);\n        }\n      }\n    }","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L1445-L1481","documentation":"Thrown by the same CSV/TSV line parser when a row ENDS with fewer fields than numColumns: at a newline outside quotes, columnI must equal numColumns-1, otherwise the line has too few columns. The exception reports columnI/numColumns and the offset of the line in the input.","triggerScenarios":"Calling the CSV reader with a numColumns larger than some row's actual field count: short/truncated lines, trailing blank lines parsed as rows, a header row with fewer fields, or data rows with optional trailing fields omitted.","commonSituations":"Files exported with ragged rows (optional last column empty and dropped); a blank line at end of file being counted as a malformed row; schema changed from 4 to 5 columns but old data files still in the pipeline; manual edits deleting a trailing comma.","solutions":["Fix or remove the short/blank lines in the source file (check for a trailing empty line).","Set numColumns to the true (consistent) column count of the data.","Pre-filter lines: skip empty lines and validate field count before feeding the parser.","If trailing fields are legitimately optional, pad short lines with empty strings before parsing."],"exampleFix":"// before\nList<String[]> cols = IOUtils.csvStringToColumns(IOUtils.slurpFileNoExceptions(f, \"UTF-8\"), 4);\n// after\nString[] rows = Arrays.stream(IOUtils.slurpFileNoExceptions(f, \"UTF-8\").split(\"\\n\"))\n                     .filter(l -> !l.trim().isEmpty()).toArray(String[]::new);\nfor (String r : rows) {\n  if (r.split(\",\").length != 4) throw new IllegalArgumentException(\"Bad row: \" + r);\n}\nList<String[]> cols = IOUtils.csvStringToColumns(String.join(\"\\n\", rows), 4);","handlingStrategy":"validation","validationCode":"String[] lines = csvText.split(\"\\n\", -1);\nif (!lines[lines.length - 1].trim().isEmpty()) { /* no trailing newline artifact */ }\nfor (int i = 0; i < lines.length; i++) {\n  if (lines[i].trim().isEmpty()) continue; // skip blank lines\n  if (lines[i].split(\",\", -1).length != numColumns)\n    throw new IllegalArgumentException(\"Line \" + (i + 1) + \" has wrong field count\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  List<String[]> cols = IOUtils.csvStringToColumns(csvText, numColumns);\n} catch (IllegalArgumentException e) {\n  throw new DataFormatException(\"Short row in CSV (offset \" + e.getMessage() + \"): fix or skip line\");\n}","preventionTips":["Strip/skip blank and header lines before parsing.","Confirm numColumns matches the current schema version of the data files.","Reject ragged files at ingestion rather than mid-parse."],"tags":["csv","parsing","validation","java"],"backgroundTag":"schema-validation-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}