{"record":{"id":"22d3c5d9e53422ab","repo":"languagetool-org/languagetool","slug":"required-key-key-not-found-in-properties","errorCode":null,"errorMessage":"Required key '${key}' not found in properties","messagePattern":"Required key '(.+?)' not found in properties","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/DatabaseHandler.java","lineNumber":87,"sourceCode":"      conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);\n      insertSt = conn.prepareStatement(insertSql);\n    } catch (SQLException | IOException e) {\n      throw new RuntimeException(e);\n    }\n    contextTools = new ContextTools();\n    contextTools.setContextSize(MAX_CONTEXT_LENGTH);\n    contextTools.setErrorMarker(MARKER_START, MARKER_END);\n    contextTools.setEscapeHtml(false);\n    smallContextTools = new ContextTools();\n    smallContextTools.setContextSize(SMALL_CONTEXT_LENGTH);\n    smallContextTools.setErrorMarker(MARKER_START, MARKER_END);\n    smallContextTools.setEscapeHtml(false);\n  }\n\n  private String getProperty(Properties prop, String key) {\n    String value = prop.getProperty(key);\n    if (value == null) {\n      throw new RuntimeException(\"Required key '\" + key + \"' not found in properties\");\n    }\n    return value;\n  }\n\n  @Override\n  protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) {\n    try {\n      java.sql.Date nowDate = new java.sql.Date(new Date().getTime());\n      for (RuleMatch match : ruleMatches) {\n        String smallContext = smallContextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText());\n        insertSt.setString(1, language.getShortCode());\n        Rule rule = match.getRule();\n        insertSt.setString(2, rule.getId());\n        insertSt.setString(3, rule.getCategory().getName());\n        if (rule instanceof AbstractPatternRule) {\n          AbstractPatternRule patternRule = (AbstractPatternRule) rule;\n          insertSt.setString(4, patternRule.getSubId());\n        } else {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/DatabaseHandler.java#L69-L105","documentation":"DatabaseHandler.getProperty requires that a database configuration key be present in the loaded Properties object; if Properties.getProperty returns null it throws a RuntimeException naming the missing key. It backs the dbUrl, dbUser, and dbPassword lookups, so any missing DB connection property aborts startup.","triggerScenarios":"The -d properties file passed to the checker lacks dbUrl, dbUser, or dbPassword, the key is misspelled, or the file is empty/loaded from the wrong path.","commonSituations":"Copying an old config template missing new keys; typos like 'databaseUrl' vs 'dbUrl'; loading a default/empty properties file because the -d option pointed elsewhere.","solutions":["Open the properties file and add the exact key named in the message (e.g. dbUrl=jdbc:mysql://...)","Check key spelling against what DatabaseHandler expects","Confirm the -d option points to the intended properties file and that it loaded non-empty content"],"exampleFix":"// before (db.properties)\ndatabaseUrl=jdbc:mysql://localhost/wiki\n// after\ndbUrl=jdbc:mysql://localhost/wiki\ndbUser=ltuser\ndbPassword=secret","handlingStrategy":"validation","validationCode":"Properties p = new Properties();\ntry (FileInputStream in = new FileInputStream(propFile)) { p.load(in); }\nfor (String key : new String[]{\"dbUrl\", \"dbUser\", \"dbPassword\"}) {\n  if (p.getProperty(key) == null) throw new IllegalStateException(\"Missing required key: \" + key);\n}","typeGuard":"static String requireProp(Properties p, String key) {\n  String v = p.getProperty(key);\n  if (v == null || v.trim().isEmpty()) throw new IllegalStateException(\"Missing/empty key: \" + key);\n  return v;\n}","tryCatchPattern":"try {\n  handler = new DatabaseHandler(props);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"not found in properties\")) {\n    System.err.println(\"Fix your properties file: \" + e.getMessage()); System.exit(2);\n  } else throw e;\n}","preventionTips":["Ship a template properties file with all required keys","Validate all keys at startup before connecting","Use a versioned config example in the repo","Assert file loaded non-empty"],"tags":["configuration","properties","database"],"backgroundTag":"missing-required-config-field","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}