{"record":{"id":"b8cdd10030e52d5b","repo":"stanfordnlp/CoreNLP","slug":"failed-to-read-lambdas-from-given-input-stream","errorCode":null,"errorMessage":"Failed to read lambdas from given input stream","messagePattern":"Failed to read lambdas from given input stream","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/maxent/iis/LambdaSolve.java","lineNumber":727,"sourceCode":"\n\n  /**\n   * Read the lambdas from the stream.\n   *\n   * @param rf Stream to read from.\n   * @return An array of lambda values read from the stream.\n   */\n  public static double[] read_lambdas(DataInputStream rf) {\n    if (VERBOSE) {\n      log.info(\"Entering read_lambdas\");\n    }\n    try {\n      ObjectInputStream ois = new ObjectInputStream(rf);\n      Object o = ois.readObject();\n      if (o instanceof double[]) {\n        return (double[]) o;\n      }\n      throw new RuntimeIOException(\"Failed to read lambdas from given input stream\");\n    } catch (IOException | ClassNotFoundException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n\n  /**\n   * This method writes the problem data into a file, which is good for reading\n   * with MatLab.  It could also have other applications,\n   * like reducing the memory requirements\n   */\n\n  void save_problem(String filename) {\n    try {\n      PrintFile pf = new PrintFile(filename);\n      int N = p.data.xSize;\n      int M = p.data.ySize;\n      int F = p.fSize;","sourceCodeStart":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/maxent/iis/LambdaSolve.java#L709-L745","documentation":"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.","triggerScenarios":"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[].","commonSituations":"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.","solutions":["Ensure the stream comes from the matching write_lambdas output, not another model file","Check the file is the expected binary serialized double[] (e.g. with a hex/file inspection)","Regenerate the lambdas file with the same Stanford NLP version that reads it"],"exampleFix":"// before\nInputStream in = new FileInputStream(cfgFile); // properties file, wrong format\ndouble[] lamb = LambdaSolve.read_lambdas(in);\n// after\nInputStream in = new FileInputStream(\"lambdas.bin\"); // produced by write_lambdas\ndouble[] lamb = LambdaSolve.read_lambdas(in);","handlingStrategy":"try-catch","validationCode":"// Verify file was produced by write_lambdas (binary Java-serialized double[]) before reading\nif (!fileHasJavaSerializationHeader(path)) { throw new IllegalArgumentException(\"Not a serialized lambdas file\"); }","typeGuard":null,"tryCatchPattern":"try { lambdas = read_lambdas(in); } catch (RuntimeIOException e) { /* wrong-format payload: check producer routine */ }","preventionTips":["Only feed streams written by the matching writer","Keep model producers and consumers on the same library version","Tag model files with format metadata"],"tags":["java","deserialization","model-loading","wrong-format"],"backgroundTag":"unexpected-response-shape","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}