{"record":{"id":"3ccbcc94d6e5d98c","repo":"stanfordnlp/CoreNLP","slug":"exception-reading-key-file-sentfilename","errorCode":null,"errorMessage":"Exception reading key file  + sentFileName","messagePattern":"Exception reading key file  \\+ sentFileName","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java","lineNumber":79,"sourceCode":"      LexicalizedParser lp = LexicalizedParser.loadModel(\"/u/nlp/data/lexparser/englishPCFG.ser.gz\", options);\n      BufferedReader reader = null;\n      try {\n        reader = IOUtils.readerFromString(sentFileName);\n      } catch (IOException e) {\n        throw new RuntimeIOException(\"Cannot find or open \" + sentFileName, e);\n      }\n      try {\n        System.out.println(\"Processing sentence file \" + sentFileName);\n        for  (String line; (line = reader.readLine()) != null; ) {\n          System.out.println(\"Processing sentence: \" + line);\n          PTBTokenizer<Word> ptb = PTBTokenizer.newPTBTokenizer(new StringReader(line));\n          List<Word> words = ptb.tokenize();\n          Tree parseTree = lp.parseTree(words);\n          tb.add(parseTree);\n        }\n        reader.close();\n      } catch (Exception e) {\n        throw new RuntimeException(\"Exception reading key file \" + sentFileName, e);\n      }\n    }\n\n    for (Tree t : tb) {\n      SemanticGraph sg = SemanticGraphFactory.generateUncollapsedDependencies(t);\n      System.out.println(sg.toString());\n      System.out.println(sg.toCompactString());\n\n      if (testGraph.equals(\"true\")) {\n        SemanticGraph g1 = SemanticGraphFactory.generateCollapsedDependencies(t);\n        System.out.println(\"TEST SEMANTIC GRAPH - graph ----------------------------\");\n        System.out.println(g1.toString());\n        System.out.println(\"readable ----------------------------\");\n        System.out.println(g1.toString(SemanticGraph.OutputFormat.READABLE));\n        System.out.println(\"List of dependencies ----------------------------\");\n        System.out.println(g1.toList());\n        System.out.println(\"xml ----------------------------\");\n        System.out.println(g1.toString(SemanticGraph.OutputFormat.XML));","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/SemanticGraphPrinter.java#L61-L97","documentation":"In SemanticGraphPrinter.main, any Exception raised while reading and parsing the sentence file (tokenizer, parser, I/O) is wrapped in RuntimeException(\"Exception reading key file \" + sentFileName). It is a generic failure wrapper indicating the key-file reading loop crashed.","triggerScenarios":"Malformed sentence text that crashes the LexicalizedParser, an I/O error mid-read (disk, encoding), or any runtime exception inside the per-line parse loop.","commonSituations":"Empty or binary/corrupt input files, unsupported character encodings, parser model issues surfacing on specific sentences.","solutions":["Inspect the wrapped cause (e.getCause()) to find the real failure","Validate the input file is plain text in the expected encoding (UTF-8) before running","Test the parser on individual sentences to isolate the offending line","Catch RuntimeException around the reader and process the file line-by-line with per-line error handling"],"exampleFix":"// before\nprinterMain(new String[]{sentFileName}); // crashes whole run on bad line\n// after\ntry {\n  printerMain(new String[]{sentFileName});\n} catch (RuntimeException e) {\n  logger.warning(\"Key file failed: \" + e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"if (sentFileName != null && new File(sentFileName).canRead()) { ... }","typeGuard":null,"tryCatchPattern":"try { printerMain(args); } catch (RuntimeException e) { log.severe(\"Key file processing failed: \" + e.getCause()); }","preventionTips":["Always inspect the wrapped cause exception","Validate input encoding (UTF-8 plain text) before parsing","Pre-test sentences individually to isolate failures"],"tags":["java","io","parsing","wrapped-exception"],"backgroundTag":"file-read-failed","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"}