{"record":{"id":"783eb28eb902d395","repo":"SonarSource/sonarqube","slug":"value-s-is-not-a-number","errorCode":null,"errorMessage":"Value '%s' is not a number","messagePattern":"Value '(.+?)' is not a number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java","lineNumber":167,"sourceCode":"  private static void processMetricCriterion(Criterion criterion, ProjectMeasuresQuery query) {\n    checkOperator(criterion);\n    checkValue(criterion);\n    query.addMetricCriterion(createMetricCriterion(criterion, criterion.getKey().toLowerCase(ENGLISH), criterion.getOperator()));\n  }\n\n  private static MetricCriterion createMetricCriterion(Criterion criterion, String metricKey, Operator operator) {\n    if (NO_DATA.equalsIgnoreCase(criterion.getValue())) {\n      checkArgument(EQ.equals(operator), \"%s can only be used with equals operator\", NO_DATA);\n      return MetricCriterion.createNoData(metricKey);\n    }\n    return MetricCriterion.create(metricKey, operator, parseValue(criterion.getValue()));\n  }\n\n  private static double parseValue(String value) {\n    try {\n      return Double.parseDouble(value);\n    } catch (NumberFormatException e) {\n      throw new IllegalArgumentException(format(\"Value '%s' is not a number\", value));\n    }\n  }\n\n  private static void checkValue(Criterion criterion) {\n    checkArgument(criterion.getValue() != null, \"Value cannot be null for '%s'\", criterion.getKey());\n  }\n\n  private static void checkOperator(Criterion criterion) {\n    checkArgument(criterion.getOperator() != null, \"Operator cannot be null for '%s'\", criterion.getKey());\n  }\n}\n","sourceCodeStart":149,"sourceCodeEnd":179,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ProjectMeasuresQueryFactory.java#L149-L179","documentation":"Metric criteria in the project measures search must carry a numeric value. parseValue, called from createMetricCriterion, uses Double.parseDouble and rethrows NumberFormatException as this IllegalArgumentException when the criterion value is not parseable as a number.","triggerScenarios":"Sending a metric criterion with a non-numeric or empty value, e.g. 'coverage >= abc', 'ncloc > \"1,000\"' (comma thousand separator), 'coverage >= ' (empty), or locale-formatted numbers like '95,5'.","commonSituations":"Copy-pasting displayed measure values (with units or separators) into filters; localization producing comma decimal separators; forgetting to quote/escape values so the parser splits incorrectly.","solutions":["Ensure the metric value is a plain number using '.' as decimal separator (e.g. 'coverage >= 80').","Strip units, currency symbols, thousands separators and whitespace from the value.","Check that the criterion did not get split so the operator/value landed in the wrong field.","Handle percentages as 0-100 numbers (e.g. coverage >= 80, not 0.8)."],"exampleFix":"// before\nString criteria = \"ncloc > 1,000\"; // comma not parseable\n// after\nString criteria = \"ncloc > 1000\";","handlingStrategy":"validation","validationCode":"if (!value.matches(\"-?\\\\d+(\\\\.\\\\d+)?\")) {\n  throw new IllegalArgumentException(\"Metric value must be a plain number with '.' decimal separator: \" + value);\n}","typeGuard":null,"tryCatchPattern":"try {\n  response = ws.searchProjects(\"coverage >= \" + value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"is not a number\")) {\n    double normalized = Double.parseDouble(value.replace(',', '.'));\n    response = ws.searchProjects(\"coverage >= \" + normalized);\n  } else throw e;\n}","preventionTips":["Normalize values programmatically: strip units/separators, replace ',' with '.'.","Format numbers with Locale.ROOT / toPlainString to avoid locale separators.","Never embed user-displayed measure strings directly into criteria."],"tags":["java","sonarqube","web-api","number-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}