stanfordnlp/CoreNLP · error · IllegalArgumentException

SpanishLexer: Invalid option value in constructor:

Error message

SpanishLexer: Invalid option value in constructor: 

What it means

SpanishLexer throws this IllegalArgumentException when a known option key receives a value not among the literals the constructor accepts. The 'untokenizable' option's switch accepts exactly noneDelete, noneInsert, firstDelete, firstKeep, allKeep; anything else hits the default branch and throws. Invalid values for known keys are fatal, unlike invalid keys.

Solutions

  1. Set untokenizable to exactly one of noneDelete, noneInsert, firstDelete, firstKeep, allKeep.
  2. Check SpanishLexer.flex constructor for the accepted values of each option key.
  3. Validate the options map before construction against the documented key/value pairs.
  4. The message includes key and value ("SpanishLexer: Invalid option value in constructor: <key>: <value>"); use it to pinpoint the bad entry.

Example fix

// before
props.put("untokenizable", "all-delete");
// after
props.put("untokenizable", "allKeep");
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> ok = new java.util.HashSet<>(java.util.Arrays.asList(
  "noneDelete","noneInsert","firstDelete","firstKeep","allKeep"));
String v = options.get("untokenizable");
if (v != null && !ok.contains(v))
  throw new IllegalArgumentException("untokenizable must be one of " + ok + ", got: " + v);

Try / catch

try {
  lex = new SpanishLexer(reader, tf, options);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("SpanishLexer: Invalid option value in constructor")) {
    options.put("untokenizable", "noneDelete");
    lex = new SpanishLexer(reader, tf, options);
  } else throw e;
}

Prevention

When it happens

Trigger: new SpanishLexer(reader, tf, options) with e.g. "untokenizable" -> "delete" or "all-delete"; or any other recognized key given an unrecognized value.

Common situations: Misspelling camelCase option values in properties files; reusing option vocabulary from other CoreNLP tokenizers; scripts generating options programmatically with wrong formats.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/spanish/process/SpanishLexer.flex:175

                untokenizable = UntokenizableOptions.NONE_DELETE;
                break;
              case "firstDelete":
                untokenizable = UntokenizableOptions.FIRST_DELETE;
                break;
              case "allDelete":
                untokenizable = UntokenizableOptions.ALL_DELETE;
                break;
              case "noneKeep":
                untokenizable = UntokenizableOptions.NONE_KEEP;
                break;
              case "firstKeep":
                untokenizable = UntokenizableOptions.FIRST_KEEP;
                break;
              case "allKeep":
                untokenizable = UntokenizableOptions.ALL_KEEP;
                break;
              default:
                throw new IllegalArgumentException("SpanishLexer: Invalid option value in constructor: " + key + ": " + value);
            }
          } else if ("strictTreebank3".equals(key)) {
            strictTreebank3 = val;
          } else {
            throw new IllegalArgumentException(String.format("%s: Invalid options key in constructor: %s%n", this.getClass().getName(), key));
          }
        }
        // this.seenUntokenizableCharacter = false; // unnecessary, it's default initialized
        if (invertible) {
          if ( ! (tf instanceof CoreLabelTokenFactory)) {
            throw new IllegalArgumentException("SpanishLexer: the invertible option requires a CoreLabelTokenFactory");
          }
          prevWord = (CoreLabel) tf.makeToken("", 0, 0);
          prevWordAfter = new StringBuilder();
        }
      }

View on GitHub (pinned to 1b7edd19c4)