{"record":{"id":"5a9fcf892efef8f1","repo":"stanfordnlp/CoreNLP","slug":"error-loading-units-from-options-unitsfilename","errorCode":null,"errorMessage":"Error loading units from \" + options.unitsFilename","messagePattern":"Error loading units from \" \\+ options\\.unitsFilename","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/qe/QuantifiableEntityExtractor.java","lineNumber":72,"sourceCode":"    extractor = createExtractor();\n  }\n\n  private CoreMapExpressionExtractor<MatchedExpression> createExtractor() {\n    List<String> filenames = StringUtils.split(options.grammarFilename, \"\\\\s*[,;]\\\\s*\");\n    return CoreMapExpressionExtractor.createExtractorFromFiles(env, filenames);\n  }\n\n  private void initEnv() {\n    env = TokenSequencePattern.getNewEnv();\n    env.setDefaultTokensAnnotationKey(CoreAnnotations.NumerizedTokensAnnotation.class);\n\n    // Do case insensitive matching\n    env.setDefaultStringMatchFlags(Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);\n    env.setDefaultStringPatternFlags(Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);\n    try {\n      Units.registerUnits(env, options.unitsFilename);\n    } catch (IOException ex)  {\n      throw new RuntimeException(\"Error loading units from \" + options.unitsFilename, ex);\n    }\n    try {\n      UnitPrefix.registerPrefixes(env, options.prefixFilename);\n    } catch (IOException ex)  {\n      throw new RuntimeException(\"Error loading prefixes from \" + options.prefixFilename, ex);\n    }\n    env.bind(\"options\", options);\n\n    env.bind(\"numcomptype\", CoreAnnotations.NumericCompositeTypeAnnotation.class);\n    env.bind(\"numcompvalue\", CoreAnnotations.NumericCompositeValueAnnotation.class);\n  }\n\n  private static void generatePrefixDefs(String infile, String outfile) throws IOException {\n    List<UnitPrefix> prefixes = UnitPrefix.loadPrefixes(infile);\n    PrintWriter pw = IOUtils.getPrintWriter(outfile);\n    pw.println(\"SI_PREFIX_MAP = {\");\n    List<String> items = new ArrayList<>();\n    for (UnitPrefix prefix : prefixes) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/qe/QuantifiableEntityExtractor.java#L54-L90","documentation":"QuantifiableEntityExtractor.initEnv calls Units.registerUnits(env, options.unitsFilename); an IOException while reading that file is wrapped in a RuntimeException naming the units file. The QE annotator cannot be initialized without its units definitions, so it fails fast during init.","triggerScenarios":"Initializing the QE extractor with options.unitsFilename pointing to a missing, unreadable, or malformed units file (Units.registerUnits throws IOException on parse/read problems).","commonSituations":"Wrong path to the QE units file (often relative to a working directory that differs at runtime), missing resource when running from a jar, or a typo in the units file option.","solutions":["Verify options.unitsFilename resolves from the process working directory; use an absolute path or classpath-resolvable resource.","Check the file exists and is readable by the process user.","Ship the units file inside the deployment/jar and load it via the classpath.","Look at the wrapped IOException cause for the exact read/parse failure."],"exampleFix":"// before\nprops.setProperty(\"qe.unitsFile\", \"units.txt\");\n// after: absolute or classpath-verified path\nprops.setProperty(\"qe.unitsFile\", \"/opt/models/qe/units.txt\");","handlingStrategy":"validation","validationCode":"File units = new File(options.unitsFilename);\nif (!units.isFile() || !units.canRead())\n  throw new IllegalArgumentException(\"Units file missing/unreadable: \" + options.unitsFilename);","typeGuard":null,"tryCatchPattern":"try {\n  extractor.init(props);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Error loading units from\")) {\n    log.severe(\"Fix qe units path: \" + e.getCause());\n  }\n  throw e;\n}","preventionTips":["Use absolute paths or classpath resources for QE units/prefix files.","Verify resource files are packaged in the jar/deployment.","Log the working directory at startup; relative paths break across environments."],"tags":["io","configuration","resource-loading","qe"],"backgroundTag":"file-not-found","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"}