SonarSource/sonarqube · error · IllegalArgumentException

Unsupported value '%s' of Measure.Level can not be converted

Error message

Unsupported value '%s' of Measure.Level can not be converted to EvaluationStatus

What it means

QualityGateMeasuresStep converts the computed global Measure.Level (OK/ERROR) into the QualityGate ConditionStatus.EvaluationStatus enum. The switch only handles OK and ERROR; any other Measure.Level value (e.g. NONE) reaching this method triggers an IllegalArgumentException, indicating an internal invariant was broken upstream.

Source

Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStep.java:129

      addProjectMeasure(project, builder);

      updateQualityGateStatusHolder(qualityGate.get(), builder);
    }
  }

  private void updateQualityGateStatusHolder(QualityGate qualityGate, QualityGateDetailsDataBuilder builder) {
    qualityGateStatusHolder.setStatus(convert(builder.getGlobalLevel()), createStatusPerCondition(qualityGate.getConditions(), builder.getEvaluatedConditions()));
  }

  private static ConditionStatus.EvaluationStatus toEvaluationStatus(Measure.Level globalLevel) {
    switch (globalLevel) {
      case OK:
        return ConditionStatus.EvaluationStatus.OK;
      case ERROR:
        return ConditionStatus.EvaluationStatus.ERROR;
      default:
        throw new IllegalArgumentException(format(
          "Unsupported value '%s' of Measure.Level can not be converted to EvaluationStatus",
          globalLevel));
    }
  }

  private static org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus convert(Measure.Level globalLevel) {
    switch (globalLevel) {
      case OK:
        return org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus.OK;
      case ERROR:
        return org.sonar.ce.task.projectanalysis.qualitygate.QualityGateStatus.ERROR;
      default:
        throw new IllegalArgumentException(format(
          "Unsupported value '%s' of Measure.Level can not be converted to QualityGateStatus",
          globalLevel));
    }
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. Inspect the evaluated quality gate and measures for the component to find why the level is not OK/ERROR
  2. Ensure the quality gate evaluation step always sets OK or ERROR before QualityGateMeasuresStep runs
  3. Upgrade SonarQube so analyzer, webapp and CE versions are aligned (mixed versions can introduce new enum values)
  4. File a bug with the stack trace if a stock quality gate produces NONE at this point
Defensive patterns

Strategy: try-catch

Validate before calling

if (globalLevel != Measure.Level.OK && globalLevel != Measure.Level.ERROR) {
  throw new IllegalStateException("Unexpected quality gate level before conversion: " + globalLevel);
}

Type guard

boolean isConvertible(Measure.Level level) {
  return level == Measure.Level.OK || level == Measure.Level.ERROR;
}

Try / catch

try {
  ConditionStatus.EvaluationStatus s = toEvaluationStatus(globalLevel);
} catch (IllegalArgumentException e) {
  // log the offending level and fail the task with diagnostics
  LOGGER.error("Quality gate level conversion failed", e);
  throw e;
}

Prevention

When it happens

Trigger: createStatusPerCondition calls toEvaluationStatus with a globalLevel that is neither Measure.Level.OK nor Measure.Level.ERROR — e.g. a measure carrying Level.NONE or null-based default produced by quality gate evaluation.

Common situations: Custom/buggy quality gate evaluation producing NONE level; plugin or version mismatch where a new Measure.Level value was introduced; corrupted computed measures for the branch.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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