SonarSource/sonarqube · warning

Could not retrieve rule with uuid

Error message

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: {}

What it means

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.

Solutions

  1. Identify the orphaned rule UUID from the log and delete its stale rows from the rules deprecated keys table (RULES_DEPRECATED_KEYS).
  2. Restore the missing rule (reinstall the plugin that provided it) if the deprecated key mapping is still needed.
  3. If caused by a broken restore, re-run database maintenance/consistency checks.
  4. Safe to ignore if the affected rules are unused, but clean up to avoid repeated warnings.

Example fix

-- before: orphaned deprecated key rows
SELECT * FROM rules_deprecated_keys WHERE rule_uuid = 'orphan-uuid';
-- after: remove stale rows
DELETE FROM rules_deprecated_keys WHERE rule_uuid = 'orphan-uuid';
Defensive patterns

Strategy: validation

Validate before calling

-- detect orphaned deprecated key rows before plugin upgrade
SELECT d.* FROM rules_deprecated_keys d
LEFT JOIN rules r ON r.uuid = d.rule_uuid
WHERE r.uuid IS NULL;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/0315edb25d11bf6f. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-webserver-core/src/main/java/org/sonar/server/rule/registration/RulesRegistrationContext.java:86

    Map<String, List<RuleParamDto>> ruleParamsByRuleUuid) {
    this.dbRules = ImmutableMap.copyOf(dbRules);
    this.known = ImmutableSet.copyOf(dbRules.values());
    this.dbDeprecatedKeysByUuid = dbDeprecatedKeysByUuid;
    this.ruleParamsByRuleUuid = ruleParamsByRuleUuid;
    this.dbRulesByDbDeprecatedKey = buildDbRulesByDbDeprecatedKey(dbDeprecatedKeysByUuid, dbRules);
  }

  private static Map<RuleKey, RuleDto> buildDbRulesByDbDeprecatedKey(Map<String, Set<SingleDeprecatedRuleKey>> dbDeprecatedKeysByUuid,
    Map<RuleKey, RuleDto> dbRules) {
    Map<String, RuleDto> dbRulesByRuleUuid = dbRules.values().stream()
      .collect(Collectors.toMap(RuleDto::getUuid, Function.identity()));

    Map<RuleKey, RuleDto> rulesByKey = new LinkedHashMap<>();
    for (Map.Entry<String, Set<SingleDeprecatedRuleKey>> entry : dbDeprecatedKeysByUuid.entrySet()) {
      String ruleUuid = entry.getKey();
      RuleDto rule = dbRulesByRuleUuid.get(ruleUuid);
      if (rule == null) {
        LOG.warn("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: {}",
          ruleUuid, entry.getValue().stream()
            .map(SingleDeprecatedRuleKey::getOldRuleKeyAsRuleKey)
            .collect(Collectors.toSet()));
      } else {
        entry.getValue().forEach(d -> rulesByKey.put(d.getOldRuleKeyAsRuleKey(), rule));
      }
    }
    return unmodifiableMap(rulesByKey);
  }

  boolean hasDbRules() {
    return !dbRules.isEmpty();
  }

  Optional<RuleDto> getDbRuleFor(RulesDefinition.Rule ruleDef) {
    RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
    Optional<RuleDto> res = Stream.concat(Stream.of(ruleKey), ruleDef.deprecatedRuleKeys().stream())

View on GitHub (pinned to 184c821202)