SonarSource/sonarqube · error · IllegalArgumentException
The quality profile cannot be restored as it contains…
Error message
The quality profile cannot be restored as it contains invalid impacts: %s
What it means
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.
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
Example fix
// before: backup contains
"impacts": "{\"SECURIRY\":\"HIGH\"}"
// after
"impacts": "{\"SECURITY\":\"HIGH\"}" Defensive patterns
Strategy: validation
Validate before calling
try {
Map<String,String> m = new ObjectMapper().readValue(impactsJson, Map.class);
m.forEach((k, v) -> {
SoftwareQuality.valueOf(k); // throws if invalid
Severity.valueOf(v); // throws if invalid
});
} catch (Exception e) {
throw new IllegalStateException("Backup impacts invalid: " + impactsJson, e);
} Type guard
boolean isValidImpactEntry(String k, String v) {
return Arrays.stream(SoftwareQuality.values()).anyMatch(q -> q.name().equals(k))
&& Arrays.stream(Severity.values()).anyMatch(s -> s.name().equals(v));
} Try / catch
try {
wsClient.post("api/qualityprofiles/restore", backup);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("The quality profile cannot be restored as it contains invalid impacts")) {
log.error("Fix impacts section of the backup file: {}", e.getMessage());
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Backup XML is not valid. Root element must be
- Fail to restore Quality profile backup, XML document is not…
- Profile ' ' cannot be deleted because its descendant named…
- Quality profile not found
- Source and target profiles are equal
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/c4c28d8dd3d4470e.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/QProfileUtils.java:42
import java.util.Map;
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.issue.impact.SoftwareQuality;
public class QProfileUtils {
private QProfileUtils() {
}
public static Map<SoftwareQuality, Severity> parseImpactsToMap(String impacts) {
ObjectMapper mapper = new ObjectMapper();
Map<SoftwareQuality, Severity> parsedMap = new EnumMap<>(SoftwareQuality.class);
try {
Map<String, String> stringMap = mapper.readValue(impacts, Map.class);
for (Map.Entry<String, String> entry : stringMap.entrySet()) {
parsedMap.put(SoftwareQuality.valueOf(entry.getKey()), Severity.valueOf(entry.getValue()));
}
} catch (Exception e) {
throw new IllegalArgumentException("The quality profile cannot be restored as it contains invalid impacts: " + impacts);
}
return parsedMap;
}
}
View on GitHub (pinned to 184c821202)