{"record":{"id":"0315edb25d11bf6f","repo":"SonarSource/sonarqube","slug":"could-not-retrieve-rule-with-uuid-referenced-by","errorCode":null,"errorMessage":"Could not retrieve rule with uuid {} referenced by a deprecated rule key. The following deprecated rule keys seem to be referencing a non-existing rule: {}","messagePattern":"Could not retrieve rule with uuid (.+?) referenced by a deprecated rule key\\. The following deprecated rule keys seem to be referencing a non-existing rule: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesRegistrationContext.java","lineNumber":86,"sourceCode":"    Map<String, List<RuleParamDto>> ruleParamsByRuleUuid) {\n    this.dbRules = ImmutableMap.copyOf(dbRules);\n    this.known = ImmutableSet.copyOf(dbRules.values());\n    this.dbDeprecatedKeysByUuid = dbDeprecatedKeysByUuid;\n    this.ruleParamsByRuleUuid = ruleParamsByRuleUuid;\n    this.dbRulesByDbDeprecatedKey = buildDbRulesByDbDeprecatedKey(dbDeprecatedKeysByUuid, dbRules);\n  }\n\n  private static Map<RuleKey, RuleDto> buildDbRulesByDbDeprecatedKey(Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid,\n    Map<RuleKey, RuleDto> dbRules) {\n    Map<String, RuleDto> dbRulesByRuleUuid = dbRules.values().stream()\n      .collect(Collectors.toMap(RuleDto::getUuid, Function.identity()));\n\n    Map<RuleKey, RuleDto> rulesByKey = new LinkedHashMap<>();\n    for (Map.Entry<String, Set<SingleDeprecatedRuleKey>> entry : dbDeprecatedKeysByUuid.entrySet()) {\n      String ruleUuid = entry.getKey();\n      RuleDto rule = dbRulesByRuleUuid.get(ruleUuid);\n      if (rule == null) {\n        LOG.warn(\"Could not retrieve rule with uuid {} referenced by a deprecated rule key. \" +\n            \"The following deprecated rule keys seem to be referencing a non-existing rule: {}\",\n          ruleUuid, entry.getValue().stream()\n            .map(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey)\n            .collect(Collectors.toSet()));\n      } else {\n        entry.getValue().forEach(d -> rulesByKey.put(d.getOldRuleKeyAsRuleKey(), rule));\n      }\n    }\n    return unmodifiableMap(rulesByKey);\n  }\n\n  boolean hasDbRules() {\n    return !dbRules.isEmpty();\n  }\n\n  Optional<RuleDto> getDbRuleFor(RulesDefinition.Rule ruleDef) {\n    RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());\n    Optional<RuleDto> res = Stream.concat(Stream.of(ruleKey), ruleDef.deprecatedRuleKeys().stream())","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesRegistrationContext.java#L68-L104","documentation":"During rule registration, SonarQube maps each rule's deprecated rule keys to the rule they belong to, keyed by rule UUID. This warning is logged when a UUID listed in the deprecated-keys table has no corresponding rule in the database, meaning orphaned deprecated-key rows reference a rule that no longer exists. Registration continues without those mappings.","triggerScenarios":"buildDbRulesByDbDeprecatedKey iterating dbDeprecatedKeysByUuid and finding dbRulesByRuleUuid.get(ruleUuid) == null — i.e. the RULES_DEPRECATED_KEYS data references a rule UUID absent from the RULES table.","commonSituations":"Rules hard-deleted from the DB while their deprecated key rows remained; partial/cleaned database restores; plugin upgrades where rules were removed but history rows lingered; manual SQL cleanup of the RULES table.","solutions":["Identify the orphaned rule UUID from the log and delete its stale rows from the rules deprecated keys table (RULES_DEPRECATED_KEYS).","Restore the missing rule (reinstall the plugin that provided it) if the deprecated key mapping is still needed.","If caused by a broken restore, re-run database maintenance/consistency checks.","Safe to ignore if the affected rules are unused, but clean up to avoid repeated warnings."],"exampleFix":"-- before: orphaned deprecated key rows\nSELECT * FROM rules_deprecated_keys WHERE rule_uuid = 'orphan-uuid';\n-- after: remove stale rows\nDELETE FROM rules_deprecated_keys WHERE rule_uuid = 'orphan-uuid';","handlingStrategy":"validation","validationCode":"-- detect orphaned deprecated key rows before plugin upgrade\nSELECT d.* FROM rules_deprecated_keys d\nLEFT JOIN rules r ON r.uuid = d.rule_uuid\nWHERE r.uuid IS NULL;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use supported upgrade paths instead of manual SQL cleanup of the RULES table","After deleting rules, ensure their deprecated key rows are removed too","Verify DB restores are complete and consistent","Periodically run the orphan-check query above"],"tags":["rules","database","referential-integrity","orphaned-data"],"backgroundTag":"record-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}