{"record":{"id":"9c28ec7cfddf4ed1","repo":"stanfordnlp/CoreNLP","slug":"propfiletoproperties-could-not-read-properties-fil","errorCode":null,"errorMessage":"propFileToProperties could not read properties file: \" + filename","messagePattern":"propFileToProperties could not read properties file: \" \\+ filename","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":1098,"sourceCode":"   * something not implemented in the {@code load()} method.\n   *\n   * @param filename A properties file to read\n   * @return The corresponding Properties object\n   */\n  public static Properties propFileToProperties(String filename) {\n    try {\n      InputStream is = new BufferedInputStream(new FileInputStream(filename));\n      Properties result = new Properties();\n      result.load(is);\n      // trim all values\n      for (String propKey : result.stringPropertyNames()){\n        String newVal = result.getProperty(propKey);\n        result.setProperty(propKey,newVal.trim());\n      }\n      is.close();\n      return result;\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"propFileToProperties could not read properties file: \" + filename, e);\n    }\n  }\n\n  /**\n   * This method converts a comma-separated String (with whitespace\n   * optionally allowed after the comma) representing properties\n   * to a Properties object.  Each property is \"property=value\".  The value\n   * for properties without an explicitly given value is set to \"true\". This can be used for a 2nd level\n   * of properties, for example, when you have a commandline argument like \"-outputOptions style=xml,tags\".\n   */\n  public static Properties stringToProperties(String str) {\n    Properties result = new Properties();\n    return stringToProperties(str, result);\n  }\n\n  /**\n   * This method updates a Properties object based on\n   * a comma-separated String (with whitespace","sourceCodeStart":1080,"sourceCodeEnd":1116,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L1080-L1116","documentation":"StringUtils.propFileToProperties loads a properties file from disk. If the load throws IOException, it is rethrown as RuntimeIOException('propFileToProperties could not read properties file: <filename>'), indicating the file could not be opened or read.","triggerScenarios":"Calling StringUtils.propFileToProperties(filename) with a path that does not exist, is a directory, or cannot be read due to permissions or I/O errors.","commonSituations":"Config file not shipped with the application; relative path resolved against an unexpected working directory; file deleted between check and read in CI; wrong resource path when intending to load from the classpath instead of the filesystem.","solutions":["Confirm the filename/path exists and is readable before calling (new File(filename).canRead())","Use an absolute path or resolve the path relative to a known base directory","If the file is a classpath resource, load it via getResourceAsStream instead of propFileToProperties"],"exampleFix":"// before\nProperties p = StringUtils.propFileToProperties(\"config.properties\"); // not in cwd\n// after\nFile f = new File(\"config.properties\");\nif (!f.canRead()) throw new IllegalStateException(\"Missing config: \" + f.getAbsolutePath());\nProperties p = StringUtils.propFileToProperties(f.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File f = new File(filename);\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"Missing properties file: \" + f.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n  Properties p = StringUtils.propFileToProperties(filename);\n} catch (RuntimeIOException e) {\n  log.error(\"Cannot load properties: \" + e.getMessage());\n  p = new Properties(); // or abort\n}","preventionTips":["Ship a default config and verify its presence at startup","Resolve config paths relative to a known base or environment variable","For bundled resources, read via the classpath rather than the filesystem"],"tags":["java","io","properties","file"],"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-16T04:17:20.429Z"}