{"record":{"id":"a19b4b5e1b28dd10","repo":"languagetool-org/languagetool","slug":"lang-parameter-missing","errorCode":null,"errorMessage":"'lang' parameter missing","messagePattern":"'lang' parameter missing","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"languagetool-server/src/main/java/org/languagetool/server/ApiV2.java","lineNumber":267,"sourceCode":"      limits.getAccount().getDefaultDictionary() != null &&\n      !limits.getAccount().getDefaultDictionary().isEmpty()) {\n      dict = limits.getAccount().getDefaultDictionary();\n    }\n    boolean deleted;\n    if(\"batch\".equals(parameters.get(\"mode\"))) { //Experimental\n      List<String> words = Arrays.asList(parameters.get(\"words\").split(\"\\\\s+\"));\n      deleted = db.deleteWordBatch(words, limits.getPremiumUid(),dict);\n      writeResponse(\"deleted\", deleted, httpExchange);\n    } else {\n      deleted = db.deleteWord(parameters.get(\"word\"), limits.getPremiumUid(), dict);\n      writeResponse(\"deleted\", deleted, httpExchange);\n    }\n  }\n\n  private void handleRuleExamplesRequest(HttpExchange httpExchange, Map<String, String> params) throws Exception {\n    ensureGetMethod(httpExchange, \"/rule/examples\");\n    if (params.get(\"lang\") == null) {\n      throw new BadRequestException(\"'lang' parameter missing\");\n    }\n    if (params.get(\"ruleId\") == null) {\n      throw new BadRequestException(\"'ruleId' parameter missing\");\n    }\n    Language lang = Languages.getLanguageForShortCode(params.get(\"lang\"));\n    JLanguageTool lt = new JLanguageTool(lang);\n    if (textChecker.config.languageModelDir != null) {\n      lt.activateLanguageModelRules(textChecker.config.languageModelDir);\n    }\n    List<Rule> rules = lt.getAllRules();\n    List<Rule> foundRules = new ArrayList<>();\n    for (Rule rule : rules) {\n      if (rule.getId().equals(params.get(\"ruleId\"))) {\n        foundRules.add(rule);\n      }\n    }\n    if (foundRules.isEmpty()) {\n      throw new PathNotFoundException(\"Rule '\" + params.get(\"ruleId\") + \"' not found for language \" + lang +","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-server/src/main/java/org/languagetool/server/ApiV2.java#L249-L285","documentation":"The GET /v2/ruleExamples endpoint needs the language short code (e.g. en-US, de-DE) to build the JLanguageTool instance for which rule examples are requested. If the 'lang' query parameter is absent, handleRuleExamplesRequest throws a BadRequestException before any further validation.","triggerScenarios":"GET /v2/ruleExamples?ruleId=SOME_RULE without '?lang=xx-YY'; parameter omitted by a template or query builder; calling the endpoint with only ruleId.","commonSituations":"Clients porting from internal APIs where the language was implicit; generic API explorers that drop empty parameters; typo'd parameter name like 'language' instead of 'lang'.","solutions":["Add the 'lang' query parameter with a valid LanguageTool short code, e.g. lang=en-US.","Check for typos: the key must be exactly 'lang', not 'language'.","Validate the short code with Languages.getLanguageForShortCode client-side equivalents to ensure the language is supported."],"exampleFix":"// before\nGET /v2/ruleExamples?ruleId=TOO_LONG_SENTENCE\n// after\nGET /v2/ruleExamples?lang=en-US&ruleId=TOO_LONG_SENTENCE","handlingStrategy":"validation","validationCode":"if (!params.lang) throw new Error('ruleExamples requires a \"lang\" short code, e.g. en-US');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build endpoint URLs from a helper that requires lang and ruleId together.","Use the exact key 'lang', not 'language'.","Validate the short code against the supported language list first."],"tags":["http","rest-api","validation","languagetool"],"backgroundTag":"missing-required-argument","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"}