stanfordnlp/CoreNLP · error · RuntimeException

Invalid mapping line:

Error message

Invalid mapping line: 

What it means

UniversalPOSMapper.loadUniversalMap reads a universal POS mapping file where every non-empty line must contain exactly two whitespace-separated tokens (source tag, universal tag). Any line that does not split into exactly 2 fields triggers this RuntimeException.

Solutions

  1. Open the mapping file and find the line that doesn't have exactly 2 whitespace-separated fields
  2. Remove comments or blank extras; one 'sourceTag<TAB>universalTag' per line
  3. Re-download the canonical universal POS mapping file matching your UD/Stanford version
  4. Validate each line in a pre-pass before loading

Example fix

// before (map file)
NOUN comment line
VERB
// after
NOUN NOUN
VERB VERB
Defensive patterns

Strategy: validation

Validate before calling

List<String> bad = new ArrayList<>();
int i = 0;
for (String line : Files.readAllLines(mapPath)) {
  i++;
  String t = line.trim();
  if (t.isEmpty()) continue;
  if (t.split("\\s+").length != 2) bad.add("line " + i + ": " + t);
}
if (!bad.isEmpty()) throw new IllegalStateException("Bad mapping lines: " + bad);

Try / catch

try {
  mapper.setup(new BufferedReader(new FileReader(mapFile)));
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Invalid mapping line")) {
    throw new IllegalArgumentException("Fix the universal POS map file: " + e.getMessage(), e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling setup() with a universal POS map file containing a line with one token, three or more tokens, or stray unquoted extra whitespace-separated content.

Common situations: Hand-edited mapping files, comments accidentally left in the map file, tab-separated files with trailing comments, or files exported from spreadsheets with extra columns.

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/30195155dbbfa547. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/pipeline/UniversalPOSMapper.java:97

        MorphoFeatureType feat = MorphoFeatureType.valueOf(optToks[0]);
        List<String> featVals = morphoSpec.getValues(feat);
        morphoSpec.activate(feat);
      }
    }
  }

  private void loadUniversalMap(String path) {
    
    LineNumberReader reader = null;
    try {
      reader = new LineNumberReader(new FileReader(path));
      
      for(String line; (line = reader.readLine()) != null;) {
        if(line.trim().equals("")) continue;
        
        String[] toks = line.trim().split("\\s+");
        if(toks.length != 2)
          throw new RuntimeException("Invalid mapping line: " + line);
        
        universalMap.put(toks[0], toks[1]);
      }
      
      reader.close();
    
    } catch (FileNotFoundException e) {
      System.err.printf("%s: File not found %s%n", this.getClass().getName(),path);
    
    } catch (IOException e) {
      int lineId = (reader == null) ? -1 : reader.getLineNumber();
      System.err.printf("%s: Error at line %d%n", this.getClass().getName(),lineId);
      e.printStackTrace();
    }
  }
}

View on GitHub (pinned to 1b7edd19c4)