{"record":{"id":"0f07097fd9f80680","repo":"SonarSource/sonarqube","slug":"metric-s-is-not-supported","errorCode":null,"errorMessage":"Metric '%s' is not supported","messagePattern":"Metric '(.+?)' is not supported","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java","lineNumber":96,"sourceCode":"    @Override\n    public Optional<Measure> createMeasure(UnitTestsCounter counter, CreateMeasureContext context) {\n      String metricKey = context.getMetric().getKey();\n      Component leaf = counter.getLeaf();\n      switch (metricKey) {\n        case TESTS_KEY:\n          return createIntMeasure(context.getComponent(), leaf, counter.testsCounter.getValue());\n        case TEST_ERRORS_KEY:\n          return createIntMeasure(context.getComponent(), leaf, counter.testsErrorsCounter.getValue());\n        case TEST_FAILURES_KEY:\n          return createIntMeasure(context.getComponent(), leaf, counter.testsFailuresCounter.getValue());\n        case SKIPPED_TESTS_KEY:\n          return createIntMeasure(context.getComponent(), leaf, counter.skippedTestsCounter.getValue());\n        case TEST_EXECUTION_TIME_KEY:\n          return createLongMeasure(context.getComponent(), leaf, counter.testExecutionTimeCounter.getValue());\n        case TEST_SUCCESS_DENSITY_KEY:\n          return createDensityMeasure(counter, context.getMetric().getDecimalScale());\n        default:\n          throw new IllegalStateException(String.format(\"Metric '%s' is not supported\", metricKey));\n      }\n    }\n\n    private static Optional<Measure> createIntMeasure(Component currentComponent, Component leafComponent, Optional<Integer> metricValue) {\n      if (metricValue.isPresent() && leafComponent.getType().isDeeperThan(currentComponent.getType())) {\n        return Optional.of(Measure.newMeasureBuilder().create(metricValue.get()));\n      }\n      return Optional.empty();\n    }\n\n    private static Optional<Measure> createLongMeasure(Component currentComponent, Component leafComponent, Optional<Long> metricValue) {\n      if (metricValue.isPresent() && leafComponent.getType().isDeeperThan(currentComponent.getType())) {\n        return Optional.of(Measure.newMeasureBuilder().create(metricValue.get()));\n      }\n      return Optional.empty();\n    }\n\n    private static Optional<Measure> createDensityMeasure(UnitTestsCounter counter, int decimalScale) {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/UnitTestMeasuresStep.java#L78-L114","documentation":"UnitTestMeasuresStep builds a Measure for a given unit-test metric key on file-level components. The switch over metricKey only supports known test metrics (tests, test_failures, test_errors, skipped_tests, test_execution_time, test_success_density); an unknown key reaching the default branch throws an IllegalStateException.","triggerScenarios":"createMeasure is invoked with a metricKey from the report/measure context that is not one of the supported unit-test metric keys, e.g. a metric fed by an analyzer or plugin that this step does not handle.","commonSituations":"A plugin registers a new unit-test metric not handled by this CE step; analyzer/server version skew introducing a new metric key; misconfigured report containing unexpected metric keys.","solutions":["Log/inspect the offending metricKey to identify which plugin or analyzer emitted it","Update or remove the plugin introducing the unsupported metric","Align analyzer and SonarQube server versions so supported metric keys match","If it is a valid new metric, it must be added to the switch in UnitTestMeasuresStep (code change/upgrade)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"private static final Set<String> SUPPORTED = Set.of(\n  \"tests\", \"test_failures\", \"test_errors\", \"skipped_tests\",\n  \"test_execution_time\", \"test_success_density\");\nboolean isSupportedTestMetric(String metricKey) { return SUPPORTED.contains(metricKey); }","typeGuard":null,"tryCatchPattern":"try {\n  Optional<Measure> m = createMeasure(context, metricKey, counters);\n} catch (IllegalStateException e) {\n  LOGGER.warn(\"Skipping unsupported unit-test metric: {}\", metricKey, e);\n}","preventionTips":["Whitelist metric keys before feeding them into UnitTestMeasuresStep","Keep analyzer and server versions aligned so emitted metric keys are supported","When adding a new test metric plugin-side, extend the switch in the same change","Log the unexpected metric key to identify the emitting plugin quickly"],"tags":["sonarqube","unit-tests","metrics","unsupported-metric"],"backgroundTag":"unsupported-operation","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"}