stanfordnlp/CoreNLP · error · RuntimeIOException

Failed to read lambdas from given input stream

Error message

Failed to read lambdas from given input stream

What it means

LambdaSolve's read_lambdas(InputStream) expects the stream's next object to be a double[] of lambda weights. If deserialization succeeds but yields any other type, the method throws RuntimeIOException because the payload is not a lambda array.

Solutions

  1. Ensure the stream comes from the matching write_lambdas output, not another model file
  2. Check the file is the expected binary serialized double[] (e.g. with a hex/file inspection)
  3. Regenerate the lambdas file with the same Stanford NLP version that reads it

Example fix

// before
InputStream in = new FileInputStream(cfgFile); // properties file, wrong format
double[] lamb = LambdaSolve.read_lambdas(in);
// after
InputStream in = new FileInputStream("lambdas.bin"); // produced by write_lambdas
double[] lamb = LambdaSolve.read_lambdas(in);
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify file was produced by write_lambdas (binary Java-serialized double[]) before reading
if (!fileHasJavaSerializationHeader(path)) { throw new IllegalArgumentException("Not a serialized lambdas file"); }

Try / catch

try { lambdas = read_lambdas(in); } catch (RuntimeIOException e) { /* wrong-format payload: check producer routine */ }

Prevention

When it happens

Trigger: Reading a file/stream that was not written by the matching save (write_lambdas) routine — the ObjectInputStream reads a valid object (e.g. a String, a different array type, or a wholly different model format) that is not double[].

Common situations: Pointing the reader at a text/properties file or a model serialized in another format; passing a stream of the wrong model component; mixing files from different tool versions.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/maxent/iis/LambdaSolve.java:727


  /**
   * Read the lambdas from the stream.
   *
   * @param rf Stream to read from.
   * @return An array of lambda values read from the stream.
   */
  public static double[] read_lambdas(DataInputStream rf) {
    if (VERBOSE) {
      log.info("Entering read_lambdas");
    }
    try {
      ObjectInputStream ois = new ObjectInputStream(rf);
      Object o = ois.readObject();
      if (o instanceof double[]) {
        return (double[]) o;
      }
      throw new RuntimeIOException("Failed to read lambdas from given input stream");
    } catch (IOException | ClassNotFoundException e) {
      throw new RuntimeIOException(e);
    }
  }


  /**
   * This method writes the problem data into a file, which is good for reading
   * with MatLab.  It could also have other applications,
   * like reducing the memory requirements
   */

  void save_problem(String filename) {
    try {
      PrintFile pf = new PrintFile(filename);
      int N = p.data.xSize;
      int M = p.data.ySize;
      int F = p.fSize;

View on GitHub (pinned to 1b7edd19c4)