{"record":{"id":"22ecc6449103b355","repo":"stanfordnlp/CoreNLP","slug":"caught-ioexception-outputting-qn-data-to-file","errorCode":null,"errorMessage":"Caught IOException outputting QN data to file","messagePattern":"Caught IOException outputting QN data to file","errorType":"exception","errorClass":"edu.stanford.nlp.io.RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":934,"sourceCode":"    } else {\n      grad = rawGrad;\n    }\n\n    PrintWriter outFile = null;\n    PrintWriter infoFile = null;\n\n    if (outputToFile) {\n      try {\n        String baseName = \"QN_m\" + mem + '_' + lsOpt.toString() + '_'\n            + scaleOpt.toString();\n        outFile = new PrintWriter(new FileOutputStream(baseName + \".output\"),\n            true);\n        infoFile = new PrintWriter(new FileOutputStream(baseName + \".info\"),\n            true);\n        infoFile.println(dFunction.domainDimension() + \"; DomainDimension \");\n        infoFile.println(mem + \"; memory\");\n      } catch (IOException e) {\n        throw new RuntimeIOException(\"Caught IOException outputting QN data to file\", e);\n      }\n    }\n\n    Record rec = new Record(monitor, functionTolerance, outFile);\n    // sets the original gradient and x. Also stores the monitor.\n    rec.start(value, rawGrad, x);\n\n    // Check if max Evaluations and Iterations have been provided.\n    maxFevals = (maxFunctionEvaluations > 0) ? maxFunctionEvaluations\n        : Integer.MAX_VALUE;\n    // maxIterations = (maxIterations > 0) ? maxIterations : Integer.MAX_VALUE;\n\n    if (!quiet) {\n      log.info(\"               An explanation of the output:\");\n      log.info(\"Iter           The number of iterations\");\n      log.info(\"evals          The number of function evaluations\");\n      log.info(\"SCALING        <D> Diagonal scaling was used; <I> Scaled Identity\");\n      log.info(\"LINESEARCH     [## M steplength]  Minpack linesearch\");","sourceCodeStart":916,"sourceCodeEnd":952,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L916-L952","documentation":"When QNMinimizer is configured to write output to files (outFile/infoFile), any IOException while opening or writing these files is wrapped in RuntimeIOException so it escapes as an unchecked exception. It signals failure to create the diagnostic/output files, not a problem with the optimization itself.","triggerScenarios":"Calling minimize() with output writing enabled (e.g. QNMinimizer set to dump function/gradient info) when the base output path is unwritable, the directory does not exist, disk is full, or a FileOutputStream to baseName + \".txt\"/\".info\" fails.","commonSituations":"Running training on a read-only filesystem, a nonexistent output directory, insufficient write permissions, or reusing a path that is locked by another process.","solutions":["Ensure the output directory exists and is writable before calling minimize().","Catch RuntimeIOException around minimize() and handle/log it.","Disable or relocate file output if it is not needed."],"exampleFix":"// before\nFile dir = new File(\"/logs/qn\");\nminimizer.minimize(f, tol, init); // RuntimeIOException if /logs/qn missing\n// after\nFile dir = new File(\"/logs/qn\");\ndir.mkdirs();\nminimizer.setOutputFile(new File(dir, \"qn-out\"));\nminimizer.minimize(f, tol, init);","handlingStrategy":"validation","validationCode":"File outDir = new File(baseName).getAbsoluteFile().getParentFile();\nif (outDir == null || !outDir.isDirectory() || !outDir.canWrite())\n  throw new IllegalStateException(\"QN output directory not writable: \" + outDir);","typeGuard":null,"tryCatchPattern":"try {\n  minimizer.minimize(f, tol, init);\n} catch (RuntimeIOException e) {\n  log.severe(\"QN output IO failed: \" + e.getMessage());\n  // retry without file output or with a new directory\n}","preventionTips":["Create the output directory (mkdirs) before training.","Verify canWrite() on the target path.","Avoid output paths on network shares or read-only containers.","Give each run a unique baseName to avoid file locks."],"tags":["io","file-write","unchecked-exception"],"backgroundTag":"file-write-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}