{"record":{"id":"289df2ca5d5c275e","repo":"stanfordnlp/CoreNLP","slug":"need-to-supply-a-parser-model-with-model","errorCode":null,"errorMessage":"Need to supply a parser model with -model","messagePattern":"Need to supply a parser model with -model","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/CacheParseHypotheses.java","lineNumber":233,"sourceCode":"        argIndex += 2;\n        continue;\n      }\n      if (args[argIndex].equalsIgnoreCase(\"-treebank\")) {\n        Pair<String, FileFilter> treebankDescription = ArgUtils.getTreebankDescription(args, argIndex, \"-treebank\");\n        argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;\n        treebanks.add(treebankDescription);\n        continue;\n      }\n      if (args[argIndex].equalsIgnoreCase(\"-numThreads\")) {\n        numThreads = Integer.parseInt(args[argIndex + 1]);\n        argIndex += 2;\n        continue;\n      }\n      throw new IllegalArgumentException(\"Unknown argument \" + args[argIndex]);\n    }\n\n    if (parserModel == null) {\n      throw new IllegalArgumentException(\"Need to supply a parser model with -model\");\n    }\n    if (output == null) {\n      throw new IllegalArgumentException(\"Need to supply an output filename with -output\");\n    }\n    if (treebanks.isEmpty()) {\n      throw new IllegalArgumentException(\"Need to supply a treebank with -treebank\");\n    }\n\n    log.info(\"Writing output to \" + output);\n    log.info(\"Loading parser model \" + parserModel);\n    log.info(\"Writing \" + dvKBest + \" hypothesis trees for each tree\");\n\n    LexicalizedParser parser = LexicalizedParser.loadModel(parserModel, \"-dvKBest\", Integer.toString(dvKBest));\n    CacheParseHypotheses cacher = new CacheParseHypotheses(parser);\n    TreeTransformer transformer = DVParser.buildTrainTransformer(parser.getOp());\n    List<Tree> sentences = new ArrayList<>();\n    for (Pair<String, FileFilter> description : treebanks) {\n      log.info(\"Reading trees from \" + description.first);","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/CacheParseHypotheses.java#L215-L251","documentation":"CacheParseHypotheses.main validates required CLI arguments after parsing and throws IllegalArgumentException if the parser model path was never supplied. The -model flag is mandatory because the tool needs a serialized DVParser to extract hypothesis trees from. It is a fail-fast guard against running with an incomplete command line.","triggerScenarios":"Running CacheParseHypotheses from the command line without passing -model <path>, or passing the flag with a typo (e.g. -models) so the parsed parserModel field stays null.","commonSituations":"Copy-pasting an example command and dropping the -model option; scripting the tool and forgetting to interpolate the model path variable; confusing this tool's flag names with those of other dvparser tools.","solutions":["Add -model /path/to/parser.ser.gz to the command line","Verify the flag spelling matches -model exactly","Run without arguments or read the usage/help output to confirm required flags"],"exampleFix":"// before\njava edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -output out.txt -treebank treebank\n// after\njava edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -output out.txt -treebank treebank","handlingStrategy":"validation","validationCode":"List<String> args = Arrays.asList(cmdArgs);\nif (!args.contains(\"-model\")) {\n    throw new IllegalArgumentException(\"CacheParseHypotheses requires -model <parserModel>\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    CacheParseHypotheses.main(args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"-model\")) {\n        System.err.println(\"Usage: add -model /path/to/parser.ser.gz\");\n    }\n}","preventionTips":["Always include -model in CacheParseHypotheses invocations","Build the command from a constant template rather than by hand","Validate the model file exists before launching the JVM"],"tags":["cli","argument-validation","stanford-corenlp"],"backgroundTag":"missing-required-argument","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"}