{"record":{"id":"926f79f8167bcbe8","repo":"stanfordnlp/CoreNLP","slug":"doesn-t-do-k-good-yet","errorCode":null,"errorMessage":"Doesn't do k good yet","messagePattern":"Doesn't do k good yet","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java","lineNumber":846,"sourceCode":"   */\n  @Override\n  public List<ScoredObject<Tree>> getBestParses() {\n    throw new UnsupportedOperationException(\"Doesn't do best parses yet\");\n  }\n\n  /** Get k good parses for the sentence.  It is expected that the\n   *  parses returned approximate the k best parses, but without any\n   *  guarantee that the exact list of k best parses has been produced.\n   *  If a class really provides k best parses functionality, it is\n   *  reasonable to also return this output as the k good parses.\n   *\n   *  @param k The number of good parses to return\n   *  @return A list of k good parses for the sentence, with\n   *         each accompanied by its score\n   */\n  @Override\n  public List<ScoredObject<Tree>> getKGoodParses(int k) {\n    throw new UnsupportedOperationException(\"Doesn't do k good yet\");\n  }\n\n  /** Get k parse samples for the sentence.  It is expected that the\n   *  parses are sampled based on their relative probability.\n   *\n   *  @param k The number of sampled parses to return\n   *  @return A list of k parse samples for the sentence, with\n   *         each accompanied by its score\n   */\n  @Override\n  public List<ScoredObject<Tree>> getKSampledParses(int k) {\n    throw new UnsupportedOperationException(\"Doesn't do k sampled yet\");\n  }\n\n}\n","sourceCodeStart":828,"sourceCodeEnd":862,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java#L828-L862","documentation":"An UnsupportedOperationException stub in ExhaustiveDependencyParser.getBestParses: this dependency parser only produces a single best parse, so requests for k-best/good parse lists are rejected as unimplemented.","triggerScenarios":"Calling getKGoodParses(k) with any k on a ParserQuery created by ExhaustiveDependencyParser.","commonSituations":"Generic code iterating over a list of parsers and requesting k-good parse approximations; dependency parser does not maintain n-best lists.","solutions":["Switch to a parser that maintains n-good lists such as FastFactoredParser or ExhaustivePCFGParser.","Catch UnsupportedOperationException and return the single best parse instead.","Request only one parse via getBestParse() when using the dependency parser."],"exampleFix":"// before\nList<ScoredObject<Tree>> good = pq.getKGoodParses(5);\n// after\nList<ScoredObject<Tree>> good;\ntry {\n  good = pq.getKGoodParses(5);\n} catch (UnsupportedOperationException e) {\n  good = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore()));\n}","handlingStrategy":"try-catch","validationCode":"boolean supportsKGood = query.getClass().getSimpleName().contains(\"PCFG\") || query.getClass().getSimpleName().contains(\"FastFactored\");","typeGuard":null,"tryCatchPattern":"try { good = pq.getKGoodParses(k); } catch (UnsupportedOperationException e) { good = Collections.singletonList(new ScoredObject<>(pq.getBestParse(), pq.getBestScore())); }","preventionTips":["Only request k-good parses from parsers documented to support them.","Prefer getBestParse() for dependency parsing.","Add unit tests covering all parser implementations your app selects."],"tags":["java","nlp","parsing","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}