{"record":{"id":"a12f18e0a7b879ad","repo":"apache/hadoop","slug":"can-t-find-metadata-for-key-name","errorCode":null,"errorMessage":"Can't find Metadata for key ${name}","messagePattern":"Can't find Metadata for key (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java","lineNumber":611,"sourceCode":"\n  /**\n   * Roll a new version of the given key generating the material for it.\n   * <p>\n   * This implementation generates the key material and calls the\n   * {@link #rollNewVersion(String, byte[])} method.\n   *\n   * @param name the basename of the key\n   * @return the name of the new version of the key\n   * @throws IOException              raised on errors performing I/O.\n   * @throws NoSuchAlgorithmException This exception is thrown when a particular\n   *                                  cryptographic algorithm is requested\n   *                                  but is not available in the environment.\n   */\n  public KeyVersion rollNewVersion(String name) throws NoSuchAlgorithmException,\n                                                       IOException {\n    Metadata meta = getMetadata(name);\n    if (meta == null) {\n      throw new IOException(\"Can't find Metadata for key \" + name);\n    }\n\n    byte[] material = generateKey(meta.getBitLength(), meta.getCipher());\n    return rollNewVersion(name, material);\n  }\n\n  /**\n   * Can be used by implementing classes to invalidate the caches. This could be\n   * used after rollNewVersion to provide a strong guarantee to return the new\n   * version of the given key.\n   *\n   * @param name the basename of the key\n   * @throws IOException raised on errors performing I/O.\n   */\n  public void invalidateCache(String name) throws IOException {\n    // NOP\n  }\n","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProvider.java#L593-L629","documentation":"The convenience method KeyProvider.rollNewVersion(String) generates fresh material from the key's stored Metadata and then delegates to rollNewVersion(name, material). If getMetadata(name) returns null - no such key in this provider - it throws 'Can't find Metadata for key <name>' before any material is generated.","triggerScenarios":"Calling rollNewVersion(name) before createKey; a typo'd or already-deleted key name; provider chain that does not include the provider actually holding the key.","commonSituations":"Automation on a fresh cluster assuming keys exist; wrong provider URI; key deleted concurrently by another admin.","solutions":["Create the key first with createKey (or `hadoop key create`)","Guard the call with getMetadata(name) != null","Verify the key exists in this specific provider with `hadoop key list -provider <uri>`"],"exampleFix":"// before\nprovider.rollNewVersion(name);\n\n// after\nif (provider.getMetadata(name) == null) {\n  provider.createKey(name, new Options(conf).setCipher(\"AES\").setBitLength(128));\n}\nprovider.rollNewVersion(name);","handlingStrategy":"validation","validationCode":"if (provider.getMetadata(name) == null) {\n  provider.createKey(name, new KeyProvider.Options(conf).setCipher(\"AES\").setBitLength(128));\n}\nprovider.rollNewVersion(name);","typeGuard":null,"tryCatchPattern":"try { provider.rollNewVersion(name); } catch (IOException e) { if (String.valueOf(e.getMessage()).startsWith(\"Can't find Metadata\")) { provider.createKey(name, new KeyProvider.Options(conf).setCipher(\"AES\").setBitLength(128)); } else { throw e; } }","preventionTips":["Provision required keys during environment setup, not lazily at first use","Guard metadata-dependent calls with getMetadata checks","Verify key existence per provider URI in diagnostics"],"tags":["java","hadoop","key-provider","not-found","key-management"],"backgroundTag":"key-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}