{"record":{"id":"b1f6012156ddccf1","repo":"binarywang/WxJava","slug":"key-may-not-have-a-null-value","errorCode":null,"errorMessage":"key may not have a null value","messagePattern":"key may not have a null value","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/res/StringManager.java","lineNumber":188,"sourceCode":"    }\n    // Return the default\n    return getManager(packageName);\n  }\n\n  /**\n   * Get a string from the underlying resource bundle or return\n   * null if the String is not found.\n   *\n   * @param key to desired resource String\n   * @return resource String matching <i>key</i> from underlying\n   * bundle or null if not found.\n   * @throws IllegalArgumentException if <i>key</i> is null.\n   */\n  public String getString(String key) {\n    if (key == null) {\n      String msg = \"key may not have a null value\";\n\n      throw new IllegalArgumentException(msg);\n    }\n\n    String str = null;\n\n    try {\n      // Avoid NPE if bundle is null and treat it like an MRE\n      if (this.bundle != null) {\n        str = this.bundle.getString(key);\n      }\n    } catch (MissingResourceException mre) {\n      //bad: shouldn't mask an exception the following way:\n      //   str = \"[cannot find message associated with key '\" + key +\n      //         \"' due to \" + mre + \"]\";\n      //     because it hides the fact that the String was missing\n      //     from the calling code.\n      //good: could just throw the exception (or wrap it in another)\n      //      but that would probably cause much havoc on existing\n      //      code.","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/res/StringManager.java#L170-L206","documentation":"Thrown by StringManager.getString(String) when key is null. StringManager is a resource-bundle wrapper; passing a null key is treated as a programming error and rejected with IllegalArgumentException before the bundle is consulted.","triggerScenarios":"Calling getString(null) directly, or passing a variable that resolved to null (a missing config key, a map lookup returning null, an uninitialised field).","commonSituations":"Building an error message key from a code that has no mapping; lookup from a properties source where the key was absent and null propagated; refactor leaving a null key path.","solutions":["Null-check the key before calling getString, or default it to a known key.","Audit callers that build keys dynamically and ensure they never pass null.","Log the caller/source of the null key to find the upstream missing value."],"exampleFix":"// before\nString msg = sm.getString(key); // key may be null\n// after\nString msg = (key == null) ? sm.getString(\"error.default\") : sm.getString(key);","handlingStrategy":"validation","validationCode":"if (key == null) throw new IllegalArgumentException(\"message key required\");\nString msg = sm.getString(key);","typeGuard":"static boolean nonNullKey(String k) { return k != null; }","tryCatchPattern":"null","preventionTips":["Null-check dynamic keys before getString.","Map missing keys to a known default key.","Log the source of null keys during development."],"tags":["i18n","resource-bundle","validation","null-check"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}