stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid metricType

Error message

Invalid metricType:${metricType}

What it means

SieveCoreferenceSystem score scoring code looks up the requested CoNLL metric type among the known scorer names (e.g. muc, bcub, ceafe, pairwise). If the metricType string (after matching) does not equal any known name, it throws this IllegalArgumentException.

Solutions

  1. Use one of the supported metric names: muc, bcub, ceafe, pairwise (lowercase)
  2. Trim and lowercase the metric string before passing it
  3. Check the dcoref scoring property (e.g. coref.scores / Conll scored metric) for typos
  4. Consult this CoreNLP version's scorer name list since supported names vary

Example fix

// before
String metric = "BCubed";
// after
String metric = "bcub";
Defensive patterns

Strategy: validation

Validate before calling

Set<String> valid = new HashSet<>(Arrays.asList("muc", "bcub", "ceafe", "pairwise"));
String m = metricType == null ? null : metricType.trim().toLowerCase();
if (m == null || !valid.contains(m)) throw new IllegalArgumentException("metricType must be one of " + valid);

Try / catch

try {
  double score = system.getFinalScore(metricType, subScoreType);
} catch (IllegalArgumentException e) {
  logger.warn("Unsupported metricType, falling back to pairwise: " + e.getMessage());
  double score = system.getFinalScore("pairwise", subScoreType);
}

Prevention

When it happens

Trigger: Calling getFinalScore / the scoring entry point with a metricType string that is not one of the recognized scorer names (case matters before/after lowercasing depending on the code path).

Common situations: Typo in the scoring metric property (e.g. 'bccub' instead of 'bcub'); passing 'B3' or other aliases not supported by this version; passing a metric name with unexpected case or whitespace.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java:1526

      i++;
    }
    metricType = metricType.toLowerCase();
    if ("combined".equals(metricType)) {
      double finalScore = (scores[0]+scores[1]+scores[3])/3;
      logger.info("Final conll score ((muc+bcub+ceafe)/3) " + scoreType + " = " + finalScore);
      return finalScore;
    } else {
      if ("bcubed".equals(metricType)) {
        metricType = "bcub";
      }
      for (i = 0; i < names.length; i++) {
        if (names[i] != null && names[i].equals(metricType)) {
          double finalScore = scores[i];
          logger.info("Final conll score (" + metricType + ") " + scoreType + " = " + finalScore);
          return finalScore;
        }
      }
      throw new IllegalArgumentException("Invalid metricType:" + metricType);
    }
  }

  /** Returns final selected score */
  private double getFinalScore(String metricType, CorefScorer.SubScoreType subScoreType) {
    metricType = metricType.toLowerCase();
    int passIndex = sieveClassNames.length - 1;
    String scoreDesc = metricType;
    double finalScore;
    switch (metricType) {
      case "combined":
        finalScore = (scoreMUC.get(passIndex).getScore(subScoreType)
            + scoreBcubed.get(passIndex).getScore(subScoreType)
            + scorePairwise.get(passIndex).getScore(subScoreType)) / 3;
        scoreDesc = "(muc + bcub + pairwise)/3";
        break;
      case "muc":
        finalScore = scoreMUC.get(passIndex).getScore(subScoreType);

View on GitHub (pinned to 1b7edd19c4)