stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown mode + mode

Error message

Unknown mode  + mode

What it means

SemanticGraphFactory.makeFromTree throws IllegalArgumentException("Unknown mode " + mode) when the SemanticGraphFactory.Mode switch has no case for the given mode; only supported dependency modes (e.g. COLLAPSED, CCPROCESSED, BASIC, ENHANCED...) are handled in the version in use.

Solutions

  1. Use a supported SemanticGraphFactory.Mode constant matching your parser version (e.g. COLLAPSED, BASIC, CCPROCESSED)
  2. Upgrade the Stanford CoreNLP jar if you need ENHANCED/ENHANCED_PLUS_PLUS modes
  3. Log/validate the mode value from config before calling the factory

Example fix

// before
SemanticGraph sg = SemanticGraphFactory.makeFromTree(tree, SemanticGraphFactory.Mode.ENHANCED, ...); // old jar
// after
SemanticGraph sg = SemanticGraphFactory.makeFromTree(tree, SemanticGraphFactory.Mode.COLLAPSED, ...);
// or upgrade corenlp to a version supporting Mode.ENHANCED
Defensive patterns

Strategy: validation

Validate before calling

Set<SemanticGraphFactory.Mode> supported = Set.of(Mode.BASIC, Mode.COLLPSED /* per version */); if (supported.contains(mode)) { makeFromTree(tree, mode, ...); }

Try / catch

try { sg = SemanticGraphFactory.makeFromTree(tree, mode, extras, filter, null); } catch (IllegalArgumentException e) { sg = SemanticGraphFactory.generateCollapsedDependencies(tree); }

Prevention

When it happens

Trigger: Calling makeFromTree/generateXxxDependencies with a Mode value not covered by the switch — typically ENHANCED or ENHANCED_PLUS_PLUS passed to an older parser version that predates those modes, or a custom/unknown Mode.

Common situations: Version mismatch: code compiled against a newer CoreNLP enum run on an older jar; reflective or config-driven mode selection supplying an invalid value.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/SemanticGraphFactory.java:264

        deps = gs.typedDependenciesEnhanced();
        break;
      case ENHANCED_PLUS_PLUS:
        deps = gs.typedDependenciesEnhancedPlusPlus();
        break;
      case COLLAPSED_TREE:
        deps = gs.typedDependenciesCollapsedTree();
        break;
      case COLLAPSED:
        deps = gs.typedDependenciesCollapsed(includeExtras);
        break;
      case CCPROCESSED:
        deps = gs.typedDependenciesCCprocessed(includeExtras);
        break;
      case BASIC:
        deps = gs.typedDependencies(includeExtras);
        break;
      default:
        throw new IllegalArgumentException("Unknown mode " + mode);
    }

    if (filter != null) {
      List<TypedDependency> depsFiltered = Generics.newArrayList();
      for (TypedDependency td : deps) {
        if (filter.test(td)) {
          depsFiltered.add(td);
        }
      }
      deps = depsFiltered;
    }

    // there used to be an if clause that filtered out the case of empty
    // dependencies. However, I could not understand (or replicate) the error
    // it alluded to, and it led to empty dependency graphs for very short fragments,
    // which meant they were ignored by the RTE system. Changed. (pado)
    // See also the SemanticGraph constructor.

View on GitHub (pinned to 1b7edd19c4)