languagetool-org/languagetool · error · RuntimeException
Incorrect number of fields: " + line
Error message
Incorrect number of fields: " + line
What it means
DativePluralsData.loadWords parses a semicolon-separated data file (Irish dative plurals) and requires exactly 4 fields per line. A line with any other field count throws this RuntimeException naming the offending line, so a malformed data resource fails fast at load time.
Source
Thrown at languagetool-language-modules/ga/src/main/java/org/languagetool/rules/ga/DativePluralsData.java:54
public static Map<String, String> getSimpleReplacements() {
return simpleReplacements;
}
/**
* Load words.
*/
private static Set<DativePluralsEntry> loadWords(String path) {
Set<DativePluralsEntry> set = new HashSet<>();
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (line.isEmpty() || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split(";");
if (parts.length != 4) {
throw new RuntimeException("Incorrect number of fields: " + line);
}
String form = parts[0];
String formModern = null;
if (form.contains(":")) {
String[] forms = form.split(":");
if (forms.length != 2) {
throw new RuntimeException("Form has more than 1 modern form:" + line);
}
form = forms[0];
formModern = forms[1];
}
String repl = parts[3];
String replModern = null;
if (repl.contains(":")) {
String[] repls = repl.split(":");
if (repls.length != 2) {
throw new RuntimeException("Replacement has more than 1 modern form:" + line);
}View on GitHub (pinned to 2e990059ce)
Solutions
- Open the resource file (e.g. src/main/resources/.../ga/dative-plurals.txt) and fix the line printed in the message to have exactly 4 semicolon-separated fields.
- If extra data is needed, add a new column consistently to every line and update the parser, not just one line.
- Check whether a value itself contains a ';' that must be removed or escaped.
- Add a unit test that loads the data file so format drift is caught in CI.
Example fix
// before (3 fields) abha; abh; NMOL // after (4 fields) abha:abhaí; abha; f; NMOL
Defensive patterns
Strategy: validation
Validate before calling
for (String line : Files.readAllLines(path)) {
if (line.isBlank() || line.startsWith("#")) continue;
if (line.split(";", -1).length != 4) throw new IllegalStateException("bad line: " + line);
} Try / catch
try { DativesData.datives(); } catch (RuntimeException e) { log.error("Data file corrupt: " + e.getMessage()); throw e; } Prevention
- Lint the data file in CI (field count, colon counts per field)
- Avoid editing data files with spreadsheet tools that alter separators
- Keep a header comment documenting the 4-field format
When it happens
Trigger: A line in the dative plurals resource file contains fewer or more than 4 semicolon-separated fields (e.g. a missing ';' or an extra one), and is not blank or commented with '#'.
Common situations: Manual edits to the .txt data file; contributors appending columns; CSV editors re-quoting or altering separators; copy-paste losing a trailing field.
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
- Form has more than 1 modern form:" + line
- Replacement has more than 1 modern form:" + line
- Could not load simple replacement data from: " + path + ". E
- Format error in file " + path + ", line: " + line
- Format error in file " + path + ", line: " + line + ", " + "
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/90a30c4dcc8e6d2a.
Report an issue: GitHub.