stanfordnlp/CoreNLP · error · InvalidObjectException

ILLEGAL VALUE IN SERIALIZED SYMBOL

Error message

ILLEGAL VALUE IN SERIALIZED SYMBOL

What it means

Symbol's readResolve/validation switch maps serialized type constants (LETTER_TYPE, BEGIN_WORD_TYPE, END_WORD_TYPE) back to enum-like constants. An unrecognized type value in a deserialized stream triggers InvalidObjectException, protecting against corrupted or version-mismatched serialization.

Solutions

  1. Reserialize the lexicon/model with the same parser version you use at load time (retrain or re-export the model)
  2. Check Stanford Parser version compatibility between the model file and your classpath jars
  3. Replace the corrupted serialized file with a fresh copy
  4. If intentionally changing the encoding, update all *_TYPE constants and bump serialVersionUID consistently

Example fix

// before: cross-version model file with parser 3.x code reading a 4.x model
ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(model)));
// after: align versions / rebuild model
// 1. run training with the SAME parser version as runtime
// 2. or catch and report:
try { sym = (Symbol) in.readObject(); }
catch (InvalidObjectException e) { throw new IOException("Incompatible model file, retrain with matching parser version", e); }
Defensive patterns

Strategy: try-catch

Validate before calling

// verify model file is a non-empty gzip stream from a matching parser version
if (!modelFile.canRead() || modelFile.length() == 0)
  throw new IOException("Missing/corrupt model: " + modelFile);

Try / catch

try { sym = (Symbol) ois.readObject(); } catch (InvalidObjectException e) { throw new IOException("Incompatible or corrupt serialized Symbol — reload model from matching parser version", e); }

Prevention

When it happens

Trigger: Deserializing a Symbol whose type byte/int is not one of the defined *_TYPE constants — corrupted .ser file, stream produced by a different (incompatible) class version, or hand-crafted/mutated serialized data.

Common situations: Loading a Chinese character lexicon serialized with an older/newer Stanford Parser version whose Symbol encoding changed; truncated or edited serialized grammar files; cross-version model reuse.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseCharacterBasedLexicon.java:516

    protected Object readResolve() throws ObjectStreamException {
      switch (type) {
        case CHAR_TYPE:
          return intern();
        case UNK_CLASS_TYPE:
          return intern();
        case UNKNOWN_TYPE:
          return UNKNOWN;
        case DIGIT_TYPE:
          return DIGIT;
        case LETTER_TYPE:
          return LETTER;
        case BEGIN_WORD_TYPE:
          return BEGIN_WORD;
        case END_WORD_TYPE:
          return END_WORD;
        default: // impossible...
          throw new InvalidObjectException("ILLEGAL VALUE IN SERIALIZED SYMBOL");
      }
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (!(o instanceof Symbol)) {
        return false;
      }

      final Symbol symbol = (Symbol) o;

      if (ch != symbol.ch) {
        return false;
      }
      if (type != symbol.type) {

View on GitHub (pinned to 1b7edd19c4)