stanfordnlp/CoreNLP · error · RuntimeException

Cannot use custom feature factory with localFeaturesOnly…

Error message

Cannot use custom feature factory with localFeaturesOnly flag--have your custom feature factory extend ArabicSegmenterFeatureFactory instead of StartAndEndArabicSegmenterFeatureFactory and remove the localFeaturesOnly flag.

What it means

ArabicSegmenter supports a special StartAndEndArabicSegmenterFeatureFactory only when localFeaturesOnly is set; a custom featureFactory combined with localFeaturesOnly is contradictory and throws this RuntimeException during construction/initialization of the segmenter.

Solutions

  1. Remove the -localFeaturesOnly flag from the properties
  2. Make your custom feature factory extend ArabicSegmenterFeatureFactory (not StartAndEndArabicSegmenterFeatureFactory) and drop localFeaturesOnly
  3. If you need local-features-only behavior with a custom factory, subclass accordingly and supply it via -featureFactory alone

Example fix

// before
props.setProperty("localFeaturesOnly", "true");
props.setProperty("featureFactory", "my.custom.Factory");
// after
props.setProperty("featureFactory", "my.custom.Factory"); // localFeaturesOnly removed
Defensive patterns

Strategy: validation

Validate before calling

Properties p = seg.props;
if (p.containsKey("localFeaturesOnly") && p.containsKey("featureFactory")) {
  throw new IllegalArgumentException("Remove -localFeaturesOnly when using a custom -featureFactory");
}

Prevention

When it happens

Trigger: Passing properties containing both optLocalFeaturesOnly (-localFeaturesOnly) and a custom optFeatureFactory (-featureFactory) to the ArabicSegmenter constructor.

Common situations: Reusing a serialized ArabicSegmenter training config that had localFeaturesOnly while adding a custom feature factory, or command-line flag accumulation from scripts.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/process/ArabicSegmenter.java:132

   * Make an Arabic Segmenter.
   *
   *  @param props Options for how to tokenize. See the main method of {@link ArabicTokenizer} for details
   */
  public ArabicSegmenter(Properties props) {
    isTokenized = props.containsKey(optTokenized);
    tokenizerOptions = props.getProperty(optTokenizer, null);
    tedEvalPrefix = props.getProperty(optTedEval, null);
    hasDomainLabels = props.containsKey(optWithDomains);
    domain = props.getProperty(optDomain, "atb");
    noRewrites = props.containsKey(optNoRewrites);
    tf = getTokenizerFactory();

    prefixMarker = props.getProperty(optPrefix, "");
    suffixMarker = props.getProperty(optSuffix, "");

    if (props.containsKey(optLocalFeaturesOnly)) {
      if (props.containsKey(optFeatureFactory))
        throw new RuntimeException("Cannot use custom feature factory with localFeaturesOnly flag--" +
            "have your custom feature factory extend ArabicSegmenterFeatureFactory instead of " +
            "StartAndEndArabicSegmenterFeatureFactory and remove the localFeaturesOnly flag.");

      props.setProperty(optFeatureFactory, localOnlyFeatureFactory);
    }
    if (!props.containsKey(optFeatureFactory))
      props.setProperty(optFeatureFactory, defaultFeatureFactory);

    // Remove all command-line properties that are specific to ArabicSegmenter
    props.remove(optTokenizer);
    props.remove(optTokenized);
    props.remove(optPrefix);
    props.remove(optSuffix);
    props.remove(optThreads);
    props.remove(optTedEval);
    props.remove(optWithDomains);
    props.remove(optDomain);
    props.remove(optNoRewrites);

View on GitHub (pinned to 1b7edd19c4)