{"record":{"id":"d54b09b86ec79e05","repo":"SonarSource/sonarqube","slug":"no-cache-entry-found-for-key","errorCode":null,"errorMessage":"No cache entry found for key: ","messagePattern":"No cache entry found for key: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/MemoryCache.java","lineNumber":55,"sourceCode":"\n  public MemoryCache(CacheLoader<K, V> loader) {\n    this.loader = loader;\n  }\n\n  @CheckForNull\n  public V getNullable(K key) {\n    V value = map.get(key);\n    if (value == null && !map.containsKey(key)) {\n      value = loader.load(key);\n      map.put(key, value);\n    }\n    return value;\n  }\n\n  public V get(K key) {\n    V value = getNullable(key);\n    if (value == null) {\n      throw new IllegalStateException(\"No cache entry found for key: \" + key);\n    }\n    return value;\n  }\n\n  /**\n   * Get values associated with keys. All the requested keys are included\n   * in the Map result. Value is null if the key is not found in cache.\n   */\n  public Map<K, V> getAll(Iterable<K> keys) {\n    List<K> missingKeys = new ArrayList<>();\n    Map<K, V> result = new HashMap<>();\n    for (K key : keys) {\n      V value = map.get(key);\n      if (value == null && !map.containsKey(key)) {\n        missingKeys.add(key);\n      } else {\n        result.put(key, value);\n      }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/MemoryCache.java#L37-L73","documentation":"MemoryCache.get(K key) is a strict lookup: it delegates to getNullable(key) and, if nothing is stored under the key, throws IllegalStateException. The compute engine's analysis steps only call get() for keys they expect to have been populated earlier in the task, so an absent entry indicates a broken internal invariant (a step ran before the step that fills the cache, or the key derivation changed).","triggerScenarios":"Calling cache.get(key) when no put(key,...) was done for that key in the current computation container; requesting a key whose underlying component/analysis was skipped or deleted; using a different key format than the one used to populate the cache.","commonSituations":"Plugin or core steps reordered so a consumer step runs before the producer step; a component referenced in a report has no matching DB row, so its cache entry was never written; custom keyspace changes during SonarQube upgrades.","solutions":["Check the compute engine step ordering: ensure the step that populates the cache (e.g. ComponentIssuesLoader / repository loaders) runs before the step calling get().","Use getNullable(key) plus an explicit null check if absence is a legitimate case in your code path.","Log/inspect the failing key and verify how it was derived versus how it was stored (same component ref/uuid).","Verify the referenced entity actually exists in the project analysis data (component was not deleted mid-analysis)."],"exampleFix":"// before\nMeasure measure = measureRepository.getMetric(component, METRIC_KEY);\n// after\nMeasure measure = measureRepository.getNullableMetric(component, METRIC_KEY);\nif (measure == null) {\n  throw new IllegalStateException(\"Metric \" + METRIC_KEY + \" missing for \" + component);\n}","handlingStrategy":"validation","validationCode":"if (cache.getNullable(key) == null) { throw new IllegalStateException(\"cache miss for \" + key); }\nV value = cache.get(key);","typeGuard":null,"tryCatchPattern":"try {\n  value = cache.get(key);\n} catch (IllegalStateException e) {\n  logger.warn(\"Cache miss: {}\", e.getMessage());\n  value = recomputeOrSkip(key);\n}","preventionTips":["Prefer getNullable when absence is a valid business case","Ensure the producing computation step runs before consumers","Keep key construction in a single shared helper so producer and consumer agree on keys"],"tags":["cache","illegal-state","sonarqube","compute-engine"],"backgroundTag":"internal-invariant-violation","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}