stanfordnlp/CoreNLP · error · java.lang.UnsupportedOperationException

This code branch left blank because we do not understand…

Error message

This code branch left blank because we do not understand what this method should do.

What it means

IndexedWord.factory() returns an anonymous LabelFactory whose newLabelFromString method throws UnsupportedOperationException with a placeholder message stating the authors never implemented it. It is an explicitly unimplemented factory method, not a data or configuration error. Any attempt to build an IndexedWord from a string through this factory fails.

Solutions

  1. Do not use factory().newLabelFromString for IndexedWord; create a CoreLabel from your string and wrap it: new IndexedWord(coreLabel).
  2. Use IndexedWord.valueOf(CoreLabel) or copy an existing label with factory().newLabel(label).
  3. Parse the string yourself (word, index, sentence index) and set them on the constructed IndexedWord.

Example fix

// before
Label l = IndexedWord.factory().newLabelFromString("went-3"); // throws
// after
CoreLabel cl = new CoreLabel();
cl.setWord("went");
IndexedWord iw = new IndexedWord(cl);
iw.setIndex(3);
Defensive patterns

Strategy: try-catch

Validate before calling

LabelFactory lf = IndexedWord.factory();
// newLabelFromString is intentionally unimplemented — never call it
// build via newLabel(existingLabel) or new IndexedWord(coreLabel) instead

Try / catch

try {
  return IndexedWord.factory().newLabelFromString(str);
} catch (UnsupportedOperationException e) {
  CoreLabel cl = new CoreLabel();
  cl.setWord(str.split("-")[0]);
  return new IndexedWord(cl);
}

Prevention

When it happens

Trigger: Calling IndexedWord.factory().newLabelFromString(s), or generic label-creation code that invokes newLabelFromString on the label factory returned by IndexedWord.factory().

Common situations: Reflection-based or generic deserialization frameworks that assume every LabelFactory supports newLabelFromString; code that builds labels uniformly from serialized string representations of dependency-graph nodes.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/IndexedWord.java:612

      @Override
      public Label newLabel(String labelStr) {
        CoreLabel coreLabel = new CoreLabel();
        coreLabel.setValue(labelStr);
        return new IndexedWord(coreLabel);
      }

      @Override
      public Label newLabel(String labelStr, int options) {
        return newLabel(labelStr);
      }

      @Override
      public Label newLabel(Label oldLabel) {
        return new IndexedWord(oldLabel);
      }

      @Override
      public Label newLabelFromString(String encodedLabelStr) {
        throw new UnsupportedOperationException("This code branch left blank" +
        " because we do not understand what this method should do.");
      }
    };
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public LabelFactory labelFactory() {
    return IndexedWord.factory();
  }

}

View on GitHub (pinned to 1b7edd19c4)