stanfordnlp/CoreNLP · error · IllegalArgumentException

Expected lines of the format original (tab) replacement. …

Error message

Expected lines of the format original (tab) replacement.  Line number  does not match.

What it means

Macros.readMacros() loads tregex macro files where each non-comment, non-blank line must be 'original<TAB>replacement'. A line without a tab separator cannot be split into two pieces and triggers IllegalArgumentException with the offending line number.

Solutions

  1. Fix the line number reported by the error so original and replacement are separated by an actual TAB character
  2. Replace space separators with tabs (editors: enable 'expand tabs off' or use sed -i 's/ /\t/')
  3. Ensure every macro line has both the original expression and its replacement
  4. Strip HTML/markdown artifacts when copying macro files from docs

Example fix

// before (macro file, space-separated)
NP noun-phrase
// after (tab-separated)
NP	noun-phrase
Defensive patterns

Strategy: validation

Validate before calling

int ln = 0;
for (String line : Files.readAllLines(macroFile)) {
  ln++;
  String t = line.trim();
  if (t.isEmpty() || t.startsWith("#")) continue;
  if (!line.contains("\t")) throw new IllegalArgumentException("Macro line " + ln + " lacks a TAB separator");
}

Try / catch

try {
  Macros.readMacros(reader, macros);
} catch (IllegalArgumentException e) {
  System.err.println(e.getMessage()); // names the bad line number
  // fix the macro file (use a real TAB), then reload
}

Prevention

When it happens

Trigger: A macro file line contains an identifier with no tab (spaces used instead of tab, or replacement missing entirely); reading a file whose lines split("\t", 2) yields fewer than 2 elements.

Common situations: Hand-editing macro files with editors that replace tabs with spaces; copying macro definitions from markdown/HTML where tabs became spaces or got lost; truncated files losing the replacement column.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/ec2a2edde0fc56f8. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/trees/tregex/Macros.java:50

    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
  }

  public static List<Pair<String, String>> readMacros(BufferedReader bin) {
    try {
      List<Pair<String, String>> macros = new ArrayList<>();
      String line;
      int lineNumber = 0;
      while ((line = bin.readLine()) != null) {
        ++lineNumber;
        String trimmed = line.trim();
        if (trimmed.equals("") || trimmed.charAt(0) == '#') {
          continue;
        }
        String[] pieces = line.split("\t", 2);
        if (pieces.length < 2) {
          throw new IllegalArgumentException("Expected lines of the format " +
                                             "original (tab) replacement.  " +
                                             "Line number " + lineNumber +
                                             " does not match.");
        }
        macros.add(new Pair<>(pieces[0], pieces[1]));
      }
      return macros;
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
  }

  public static void addAllMacros(TregexPatternCompiler compiler,
                                  String filename, String encoding) {
    if (filename == null || filename.equals("")) {
      return;
    }
    for (Pair<String, String> macro : readMacros(filename, encoding)) {

View on GitHub (pinned to 1b7edd19c4)