{"record":{"id":"c4c28d8dd3d4470e","repo":"SonarSource/sonarqube","slug":"the-quality-profile-cannot-be-restored-as-it-conta-c4c28d","errorCode":null,"errorMessage":"The quality profile cannot be restored as it contains invalid impacts: %s","messagePattern":"The quality profile cannot be restored as it contains invalid impacts: (.+?)","errorType":"http","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileUtils.java","lineNumber":42,"sourceCode":"import java.util.Map;\nimport org.sonar.api.issue.impact.Severity;\nimport org.sonar.api.issue.impact.SoftwareQuality;\n\npublic class QProfileUtils {\n\n  private QProfileUtils() {\n  }\n\n  public static Map<SoftwareQuality, Severity> parseImpactsToMap(String impacts) {\n    ObjectMapper mapper = new ObjectMapper();\n    Map<SoftwareQuality, Severity> parsedMap = new EnumMap<>(SoftwareQuality.class);\n    try {\n      Map<String, String> stringMap = mapper.readValue(impacts, Map.class);\n      for (Map.Entry<String, String> entry : stringMap.entrySet()) {\n        parsedMap.put(SoftwareQuality.valueOf(entry.getKey()), Severity.valueOf(entry.getValue()));\n      }\n    } catch (Exception e) {\n      throw new IllegalArgumentException(\"The quality profile cannot be restored as it contains invalid impacts: \" + impacts);\n    }\n    return parsedMap;\n  }\n}\n","sourceCodeStart":24,"sourceCodeEnd":47,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileUtils.java#L24-L47","documentation":"Thrown by QProfileUtils.parseImpactsToMap when deserializing the 'impacts' JSON of a quality profile backup fails or contains keys/values that are not valid SoftwareQuality or Severity enum names. SonarQube validates profile import payloads strictly, so any malformed impact entry aborts the whole restore with this IllegalArgumentException.","triggerScenarios":"Calling the api/qualityprofiles/restore WS with a backup whose 'impacts' JSON has an unknown software quality key (e.g. 'SECURITY' vs 'SECURITY'), an unknown severity value, non-JSON content, or a structure that is not a flat string-to-string map.","commonSituations":"Restoring a profile exported from a newer SonarQube version into an older one (enum values renamed/added); hand-edited backup files; importing a backup from a different product edition or plugin that wrote non-standard impacts.","solutions":["Open the backup file, locate the 'impacts' JSON and verify every key is a valid SoftwareQuality name and every value a valid Severity name","Remove or correct the invalid impact entries in the backup file and retry the restore","Ensure the target SonarQube version is >= the version the backup was exported from","Re-export the profile from a source instance of a compatible version instead of editing the file manually"],"exampleFix":"// before: backup contains\n\"impacts\": \"{\\\"SECURIRY\\\":\\\"HIGH\\\"}\"\n// after\n\"impacts\": \"{\\\"SECURITY\\\":\\\"HIGH\\\"}\"","handlingStrategy":"validation","validationCode":"try {\n  Map<String,String> m = new ObjectMapper().readValue(impactsJson, Map.class);\n  m.forEach((k, v) -> {\n    SoftwareQuality.valueOf(k);   // throws if invalid\n    Severity.valueOf(v);          // throws if invalid\n  });\n} catch (Exception e) {\n  throw new IllegalStateException(\"Backup impacts invalid: \" + impactsJson, e);\n}","typeGuard":"boolean isValidImpactEntry(String k, String v) {\n  return Arrays.stream(SoftwareQuality.values()).anyMatch(q -> q.name().equals(k))\n      && Arrays.stream(Severity.values()).anyMatch(s -> s.name().equals(v));\n}","tryCatchPattern":"try {\n  wsClient.post(\"api/qualityprofiles/restore\", backup);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"The quality profile cannot be restored as it contains invalid impacts\")) {\n    log.error(\"Fix impacts section of the backup file: {}\", e.getMessage());\n  }\n}","preventionTips":["Never hand-edit backup JSON; always re-export from a compatible instance","Keep source and target SonarQube versions aligned (target >= source)","Validate enum names with valueOf before importing custom backups"],"tags":["sonarqube","quality-profile","json-parsing","enum-validation"],"backgroundTag":"json-unmarshal-failed","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"}