{"record":{"id":"074b8cbada102c6f","repo":"apache/hadoop","slug":"problem-looking-up-key-name-in-this","errorCode":null,"errorMessage":"Problem looking up key ${name} in ${this}","messagePattern":"Problem looking up key (.+?) in (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/JavaKeyStoreProvider.java","lineNumber":445,"sourceCode":"      }\n    } finally {\n      readLock.unlock();\n    }\n  }\n\n  @Override\n  public KeyVersion createKey(String name, byte[] material,\n                               Options options) throws IOException {\n    Preconditions.checkArgument(name.equals(StringUtils.toLowerCase(name)),\n        \"Uppercase key names are unsupported: %s\", name);\n    writeLock.lock();\n    try {\n      try {\n        if (keyStore.containsAlias(name) || cache.containsKey(name)) {\n          throw new IOException(\"Key \" + name + \" already exists in \" + this);\n        }\n      } catch (KeyStoreException e) {\n        throw new IOException(\"Problem looking up key \" + name + \" in \" + this,\n            e);\n      }\n      Metadata meta = new Metadata(options.getCipher(), options.getBitLength(),\n          options.getDescription(), options.getAttributes(), new Date(), 1);\n      if (options.getBitLength() != 8 * material.length) {\n        throw new IOException(\"Wrong key length. Required \" +\n            options.getBitLength() + \", but got \" + (8 * material.length));\n      }\n      cache.put(name, meta);\n      String versionName = buildVersionName(name, 0);\n      return innerSetKeyVersion(name, versionName, material, meta.getCipher());\n    } finally {\n      writeLock.unlock();\n    }\n  }\n\n  @Override\n  public void deleteKey(String name) throws IOException {","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/JavaKeyStoreProvider.java#L427-L463","documentation":"At the start of createKey(), the pre-existence check itself (keyStore.containsAlias) threw KeyStoreException — the keystore object is uninitialized or in a failed state, so the provider cannot even check whether the key exists. Wrapped as IOException('Problem looking up key ...') with the cause attached.","triggerScenarios":"Calling createKey() against a provider whose KeyStore was never initialized or whose load failed earlier — common in tests with mock/partial keystores, or when the keystore file disappeared while a provider instance was live.","commonSituations":"Unit tests mocking KeyStore without calling load(); KMS process holding a handle to a deleted/moved keystore file; provider reuse after a swallowed load error","solutions":["Recreate/reload the provider so load() runs cleanly, then retry createKey","Confirm the keystore path exists and passes keytool -list before invoking the provider","In tests, back the provider with a real (temporary) JCEKS file instead of mocks"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify provider health before create paths\ntry {\n  provider.getKeys(); // cheap structural probe\n} catch (IOException e) {\n  throw new IllegalStateException(\"Keystore not initialized/healthy\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  provider.createKey(name, material, options);\n} catch (IOException e) {\n  if (e.getCause() instanceof KeyStoreException) {\n    // provider state broken: build a fresh provider instance and retry once\n  }\n}","preventionTips":["Instantiate a fresh provider after keystore load failures instead of reusing it","In tests, initialize real JCEKS files; don't mock KeyStore partially","Probe with getKeys() before write operations in long-lived services"],"tags":["keystore","kms","crypto","key-lookup","create-key"],"backgroundTag":"keystore-key-lookup-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}