{"record":{"id":"d1a69e2f4d2248dd","repo":"SonarSource/sonarqube","slug":"specified-rulekey-s-is-not-equal-to-the-one-alr","errorCode":null,"errorMessage":"Specified RuleKey '%s' is not equal to the one already registered in repository for ref %s: '%s'","messagePattern":"Specified RuleKey '(.+?)' is not equal to the one already registered in repository for ref (.+?): '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/RuleRepositoryImpl.java","lineNumber":41,"sourceCode":"import java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\nimport org.sonar.api.rule.RuleKey;\n\nimport static java.lang.String.format;\nimport static java.util.Objects.requireNonNull;\n\npublic class RuleRepositoryImpl implements RuleRepository {\n  private final Map<String, Rule> rulesByUuid = new HashMap<>();\n\n  @Override\n  public Rule register(String ref, RuleKey ruleKey) {\n    requireNonNull(ruleKey, \"ruleKey can not be null\");\n\n    Rule rule = rulesByUuid.get(ref);\n    if (rule != null) {\n      if (!ruleKey.repository().equals(rule.repository()) || !ruleKey.rule().equals(rule.key())) {\n        throw new IllegalArgumentException(format(\n          \"Specified RuleKey '%s' is not equal to the one already registered in repository for ref %s: '%s'\",\n          ruleKey, ref, RuleKey.of(rule.repository(), rule.key())));\n      }\n      return rule;\n    }\n\n    rule = new Rule(ref, ruleKey.repository(), ruleKey.rule());\n    rulesByUuid.put(ref, rule);\n    return rule;\n  }\n\n  @Override\n  public Collection<Rule> getAll() {\n    return List.copyOf(rulesByUuid.values());\n  }\n\n}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/rule/RuleRepositoryImpl.java#L23-L59","documentation":"RuleRepositoryImpl.register() keeps a map from a dump ref to the rule registered under it. If a ref is registered twice with a different RuleKey than the one already stored, an IllegalArgumentException is thrown because two different rules are being mapped to the same reference, which would corrupt the dump's rule index. Registering the same identical RuleKey under a ref is idempotent and returns the existing Rule.","triggerScenarios":"Calling register(ref, ruleKey) for a ref that already holds a Rule whose repository() or key() differs from the supplied RuleKey — i.e. a ref/reason collision between two distinct rules during export.","commonSituations":"A bug in a step computing refs (hash/ID collisions) reusing the same ref for different rules; re-registering rules from different repositories under the same ref during a custom/patched export.","solutions":["Find which step calls register() with the colliding ref and why two distinct RuleKeys map to it","Ensure refs are derived from a unique property of the rule (uuid or full RuleKey) instead of a colliding value","If the ref should map to the same rule, verify the exact repository and rule name spelling (case) matches the earlier registration"],"exampleFix":"// before: ref derived from rule name only, can collide across repos\nString ref = hash(rule.key());\n// after: include repository in ref\nString ref = hash(rule.repository() + \":\" + rule.key());","handlingStrategy":"validation","validationCode":"Rule existing = repositoryLookup(ref);\nif (existing != null && !ruleKey.repository().equals(existing.repository())) {\n  throw new IllegalArgumentException(\"ref collision: \" + ref);\n}","typeGuard":null,"tryCatchPattern":"try { ruleRepository.register(ref, ruleKey); } catch (IllegalArgumentException e) { logger.error(\"Ref {} already maps to a different rule\", ref, e); }","preventionTips":["Derive refs from unique rule identity (uuid or repository:name), never from colliding hashes","Check for an existing registration before registering a new ref","Write unit tests covering duplicate ref registration"],"tags":["sonarqube","project-export","rules","duplicate-key"],"backgroundTag":"invalid-argument-value","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"}