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

The CoreLabel factory (labelFactory) implements Label.newLabelFromString as a deliberately unimplemented stub: it throws UnsupportedOperationException with a message stating the branch was left blank because the intended semantics were unclear. There is no input that avoids this; the operation simply does not exist on this factory.

Solutions

  1. Do not call newLabelFromString on the CoreLabel factory; create labels with new CoreLabel(word) or new CoreLabel(String word, String tag) instead.
  2. Parse the string yourself and construct a CoreLabel (e.g. new CoreLabel(value)) rather than delegating to the factory method.
  3. If you need factory-based string reconstruction, use a Label implementation that supports it (e.g. StringLabel/Word via their factories), or convert after construction.

Example fix

// before
Label label = CoreLabel.labelFactory().newLabelFromString("dog"); // always throws
// after
CoreLabel label = new CoreLabel("dog");
Defensive patterns

Strategy: fallback

Validate before calling

// java
Label.Factory f = label.factory();
Label l;
try {
  l = f.newLabelFromString(s);
} catch (UnsupportedOperationException e) {
  l = new CoreLabel(s);
}

Type guard

// java
static boolean supportsNewLabelFromString(Label.Factory f) {
  return !(f instanceof CoreLabel.Factory);
}

Try / catch

// java
Label label;
try {
  label = factory.newLabelFromString(s);
} catch (UnsupportedOperationException e) {
  label = new CoreLabel(s); // explicit construction fallback
}

Prevention

When it happens

Trigger: Calling CoreLabel.Factory (CoreLabel.labelFactory()).newLabelFromString(String) — or routing any code path (e.g. generic Label serialization/reconstruction utilities) through it.

Common situations: Generic code that calls newLabelFromString on any Label implementation (e.g. valueOf-style frameworks) hitting a CoreLabel factory; porting code that used LabelFactory.valueof or StringLabel-style factories.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/CoreLabel.java:315

        if (oldLabel instanceof HasTag)
          label.setTag(((HasTag) oldLabel).tag());
        if (oldLabel instanceof HasOffset) {
          label.setBeginPosition(((HasOffset) oldLabel).beginPosition());
          label.setEndPosition(((HasOffset) oldLabel).endPosition());
        }
        if (oldLabel instanceof HasCategory)
          label.setCategory(((HasCategory) oldLabel).category());
        if (oldLabel instanceof HasIndex)
          label.setIndex(((HasIndex) oldLabel).index());

        label.setValue(oldLabel.value());

        return label;
      }
    }

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

  }


  /**
   * Return a factory for this kind of label
   *
   * @return The label factory
   */
  public static LabelFactory factory() {
    return new CoreLabelFactory();
  }

  /**
   * {@inheritDoc}

View on GitHub (pinned to 1b7edd19c4)