{"record":{"id":"f86e7f0fffd00859","repo":"stanfordnlp/CoreNLP","slug":"cannot-open-null-document-path","errorCode":null,"errorMessage":"Cannot open null document path!","messagePattern":"Cannot open null document path!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/DocumentPreprocessor.java","lineNumber":133,"sourceCode":"  public DocumentPreprocessor(String docPath) {\n    this(docPath, DocType.Plain, \"UTF-8\");\n  }\n\n  public DocumentPreprocessor(String docPath, DocType t) {\n    this(docPath, t, \"UTF-8\");\n  }\n\n\n  /**\n   * Constructs a preprocessor from a file at a path, which can be either\n   * a filesystem location, a classpath entry, or a URL.\n   *\n   * @param docPath The path\n   * @param encoding The character encoding used by Readers\n   */\n  public DocumentPreprocessor(String docPath, DocType t, String encoding) {\n    if (docPath == null) {\n      throw new IllegalArgumentException(\"Cannot open null document path!\");\n    }\n\n    docType = t;\n    try {\n      inputReader = IOUtils.readerFromString(docPath, encoding);\n    } catch (IOException ioe) {\n      throw new RuntimeIOException(String.format(\"%s: Could not open path %s\", this.getClass().getName(), docPath),\n              ioe);\n    }\n  }\n\n  /**\n   * Set whether or not the tokenizer keeps empty sentences in\n   * whitespace mode.  Useful for programs that want to echo blank\n   * lines.  Not relevant for the non-whitespace model.\n   */\n  public void setKeepEmptySentences(boolean keepEmptySentences) {\n    this.keepEmptySentences = keepEmptySentences;","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/DocumentPreprocessor.java#L115-L151","documentation":"The DocumentPreprocessor(String docPath, DocType, String encoding) constructor refuses a null docPath with this IllegalArgumentException. Without a path there is no file to open, so the constructor fails fast before attempting IO.","triggerScenarios":"Calling new DocumentPreprocessor(null, DocType.Plain, \"UTF-8\") or any variant of the path-based constructor with a null path — e.g. when the path comes from a config option, CLI argument, or method parameter that was never set.","commonSituations":"Missing command-line/config value for the input file; code path that conditionally sets the document path but the condition did not hold; property loaded from an incomplete configuration file.","solutions":["Ensure the docPath variable is populated before construction (check CLI args / config loading)","Provide a default path or fail earlier with a clear message when the path option is absent","Use the Reader-based constructor instead if you already have the content in memory","Add a null/empty check on the path at the boundary of your program and report a user-friendly error"],"exampleFix":"// before\nDocumentPreprocessor dp = new DocumentPreprocessor(opts.docPath, DocType.Plain, \"UTF-8\");\n// after\nif (opts.docPath == null) {\n  throw new IllegalArgumentException(\"Usage error: --docPath is required\");\n}\nDocumentPreprocessor dp = new DocumentPreprocessor(opts.docPath, DocType.Plain, \"UTF-8\");","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(docPath, \"docPath must be set (CLI --docPath or config)\");\nif (docPath.trim().isEmpty()) throw new IllegalArgumentException(\"docPath is empty\");","typeGuard":"static String requirePath(String p) {\n  if (p == null || p.trim().isEmpty()) throw new IllegalArgumentException(\"Document path missing\");\n  return p;\n}","tryCatchPattern":"try {\n  DocumentPreprocessor dp = new DocumentPreprocessor(docPath, DocType.Plain, \"UTF-8\");\n} catch (IllegalArgumentException e) {\n  if (\"Cannot open null document path!\".equals(e.getMessage())) {\n    throw new UsageException(\"No input document path supplied\", e);\n  }\n  throw e;\n}","preventionTips":["Validate CLI/config inputs at program startup, before any library call","Give required path options explicit defaults or hard failures with usage messages","Check config files for missing keys during load"],"tags":["null","path","constructor","illegal-argument","missing-config"],"backgroundTag":"null-argument","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"}