SonarSource/sonarqube · warning

Failed to parse duration threshold

Error message

Failed to parse duration threshold: {}, using raw value instead

What it means

QualityGateConditionFormatter.formatThreshold logs this warning when a WORK_DUR (work duration) metric threshold cannot be parsed as a long number of minutes, and falls back to returning the raw threshold string in the notification text. Formatting continues; only the human-readable duration formatting is skipped.

Solutions

  1. Fix the quality gate condition so its threshold is a plain integer number of minutes (e.g. '30', '480')
  2. Re-create the condition via UI or api/qualitygates/update with a numeric value
  3. If you own the calling code, validate the threshold parses before setting it on the condition

Example fix

// before
setCondition(metric="new_reliability_rating_effort", threshold="2d");
// after
setCondition(metric="new_reliability_rating_effort", threshold="480"); // minutes
Defensive patterns

Strategy: validation

Validate before calling

long threshold;
try {
  threshold = Long.parseLong(rawThreshold);
} catch (NumberFormatException e) {
  throw new IllegalArgumentException("WORK_DUR condition threshold must be an integer number of minutes, got: " + rawThreshold);
}

Prevention

When it happens

Trigger: formatThreshold is called with metricType WORK_DUR and a threshold string where Long.parseLong(threshold) throws NumberFormatException — e.g. '2d', '1h30', 'abc', or an empty string stored in the condition's warning/error threshold.

Common situations: A quality gate condition was created/edited via the web API with a non-numeric threshold for a WORK_DUR metric like 'reliability remediation effort'; data imported from a modified DB; locale-prefixed values pasted into the UI.

Understand the failure class

Related errors


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

Appendix: source

Thrown at server/sonar-server-common/src/main/java/org/sonar/server/qualitygate/notification/QualityGateConditionFormatter.java:105

    String translatedMetricName = getTranslatedMetricName(metricKey, metricName);
    String operatorLabel = OPERATOR_LABELS.get(operator);
    String formattedThreshold = formatThreshold(threshold, metricType);

    return translatedMetricName + " " + operatorLabel + " " + formattedThreshold;
  }

  private String getTranslatedMetricName(String metricKey, @Nullable String defaultName) {
    String fallback = defaultName != null ? defaultName : metricKey;
    return i18n.message(Locale.ENGLISH, "metric." + metricKey + ".name", fallback);
  }

  private String formatThreshold(String threshold, @Nullable String metricType) {
    if (Metric.ValueType.WORK_DUR.name().equals(metricType)) {
      try {
        long durationInSeconds = Long.parseLong(threshold);
        return durations.format(Duration.create(durationInSeconds));
      } catch (NumberFormatException e) {
        LOGGER.warn("Failed to parse duration threshold: {}, using raw value instead", threshold, e);
      }
    }
    return threshold;
  }

}

View on GitHub (pinned to 184c821202)