{"record":{"id":"9d603e648bfcf08d","repo":"stanfordnlp/CoreNLP","slug":"attempt-to-get-word-when-sentence-and-lattice-are","errorCode":null,"errorMessage":"attempt to get word when sentence and lattice are null!","messagePattern":"attempt to get word when sentence and lattice are null!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java","lineNumber":1594,"sourceCode":"            IntTaggedWord itw = new IntTaggedWord(edge.word, stateIndex.get(goal), wordIndex, tagIndex);\n\n            float tagScore = (floodTags) ? -1000.0f : lex.score(itw, start, edge.word, null);\n            if (matches(bestScore, tagScore + (float) edge.weight)) {\n              wordNode = tf.newLeaf(edge.word);\n              if(wordNode.label() instanceof CoreLabel) {\n              \tCoreLabel cl = (CoreLabel) wordNode.label();\n              \tcl.setBeginPosition(start);\n              \tcl.setEndPosition(end);\n              }\n              break;\n            }\n          }\n          if (wordNode == null) {\n            throw new RuntimeException(\"could not find matching word from lattice in parse reconstruction\");\n          }\n\n        } else {\n          throw new RuntimeException(\"attempt to get word when sentence and lattice are null!\");\n        }\n        Tree tagNode = tf.newTreeNode(goalStr, Collections.singletonList(wordNode));\n        tagNode.setScore(bestScore);\n        if (originalTags[start] != null) {\n          tagNode.label().setValue(originalTags[start].tag());\n        }\n        return tagNode;\n      } else {  // normal lexicon is single words case\n        IntTaggedWord tagging = new IntTaggedWord(words[start], tagIndex.indexOf(goalStr));\n        String contextStr = getCoreLabel(start).originalText();\n        float tagScore = lex.score(tagging, start, wordIndex.get(words[start]), contextStr);\n        if (tagScore > Float.NEGATIVE_INFINITY || floodTags) {\n          // return a pre-terminal tree\n          CoreLabel terminalLabel = getCoreLabel(start);\n\n          Tree wordNode = tf.newLeaf(terminalLabel);\n          Tree tagNode = tf.newTreeNode(goalStr, Collections.singletonList(wordNode));\n          tagNode.setScore(bestScore);","sourceCodeStart":1576,"sourceCodeEnd":1612,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java#L1576-L1612","documentation":"During lattice-based parse reconstruction, ExhaustivePCFGParser expects either the sentence tokens or a word lattice to be available. If both are null when it tries to fetch a word for a tag node, it throws this RuntimeException, signaling an uninitialized parse state.","triggerScenarios":"Requesting getBestParse() (reconstruction) when the query was not populated via parse(...) with a sentence or lattice, or internal state (sentence/lattice fields) was never set, e.g. calling getBestParse() without a prior successful parse call.","commonSituations":"Calling getBestParse() before calling parse(); a parse failed (returned false) but reconstruction was still attempted; programmatic use constructing the ParserQuery without proper input.","solutions":["Always check parserQuery.parse(...) returned true before calling getBestParse().","Ensure the sentence or lattice was supplied to the parser before reconstruction.","Initialize the parser query through the normal parse pipeline rather than manipulating internal fields."],"exampleFix":"// before\nparserQuery.getBestParse(); // parse never called or failed\n// after\nif (parserQuery.parse(sentence)) {\n  Tree t = parserQuery.getBestParse();\n}","handlingStrategy":"validation","validationCode":"if (!pq.parse(sentence)) { throw new IllegalStateException(\"parse failed; no reconstruction possible\"); }\nTree t = pq.getBestParse();","typeGuard":null,"tryCatchPattern":"try { t = pq.getBestParse(); } catch (RuntimeException e) { if (e.getMessage().contains(\"sentence and lattice are null\")) { /* parse was never run or failed */ } else throw e; }","preventionTips":["Always check the boolean result of parse() before reconstruction.","Never call getBestParse() without a prior successful parse on the same query.","Keep sentence/lattice inputs under the same ParserQuery instance that parsed them."],"tags":["java","nlp","parsing","null","state"],"backgroundTag":"invalid-state-transition","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"}