{"record":{"id":"72610d0f17fd44cb","repo":"SonarSource/sonarqube","slug":"can-t-read-svg-template-s","errorCode":null,"errorMessage":"Can't read svg template '%s'","messagePattern":"Can't read svg template '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/SvgGenerator.java","lineNumber":173,"sourceCode":"  }\n\n  public String generateQualityGate(Metric.Level level) {\n    return qualityGateTemplates.get(level);\n  }\n\n  public String generateError(String error) {\n    Map<String, String> values = ImmutableMap.of(\n      PARAMETER_TOTAL_WIDTH, valueOf(MARGIN + computeWidth(error) + MARGIN),\n      PARAMETER_LABEL, error);\n    StringSubstitutor strSubstitutor = new StringSubstitutor(values);\n    return strSubstitutor.replace(errorTemplate);\n  }\n\n  public static String readTemplate(String template, Class<?> clazz) {\n    try {\n      return IOUtils.toString(clazz.getResource(template), UTF_8);\n    } catch (IOException e) {\n      throw new IllegalStateException(String.format(\"Can't read svg template '%s'\", template), e);\n    }\n  }\n\n  private static int computeWidth(String text) {\n    return text.chars()\n      .mapToObj(i -> (char) i)\n      .mapToInt(c -> {\n        Integer length = CHAR_LENGTH.get(c);\n        checkState(length != null, \"Invalid character '%s'\", c);\n        return length;\n      })\n      .sum();\n  }\n\n  private String readTemplate(String template) {\n    return readTemplate(template, getClass());\n  }\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/SvgGenerator.java#L155-L191","documentation":"SvgGenerator.readTemplate loads a badge SVG template from the classpath via clazz.getResource(template); if reading the resource throws an IOException it wraps it in this IllegalStateException. This is an internal deployment/classpath problem — the template resource should always be bundled inside the SonarQube webapp.","triggerScenarios":"Rendering a quality gate or measure badge when the SVG template resource cannot be read from the jar/classpath (missing/corrupt sonar-webapi jar, broken deployment artifact).","commonSituations":"Partially extracted or corrupted SonarQube installation; a custom classloader/packaging that excludes .svg resources; running a repackaged/hacked WAR.","solutions":["Re-install SonarQube from an official, unmodified distribution","Verify the SVG template files exist inside the server JARs (unzip and check)","Ensure no custom plugin/shading step strips resources from the webapp jars","Clear any stale extracted artifacts and restart the server"],"exampleFix":"// before (corrupted install)\nsonarqube/lib/sonar-webapi-webapi-*.jar  (missing measure.svg template)\n// after\nre-download and deploy the official SonarQube distribution","handlingStrategy":"try-catch","validationCode":"// Deployment self-check: the badge SVG templates must be on the classpath\nURL tpl = SvgGenerator.class.getResource(\"/svg/measure.svg\");\nif (tpl == null) throw new IllegalStateException(\"SVG badge templates missing from classpath — reinstall SonarQube\");","typeGuard":null,"tryCatchPattern":"try {\n  String svg = SvgGenerator.readTemplate(template, clazz);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Can't read svg template\")) {\n    log.error(\"Badge template unreadable — verify server installation integrity\", e);\n    return fallbackBadgeSvg();\n  } else { throw e; }\n}","preventionTips":["Deploy only official SonarQube distributions; avoid repackaged jars","Verify jar integrity (checksums) after manual upgrades","Keep the install dir free of custom shading/plugins that strip .svg resources","Smoke-test badge rendering after every server upgrade"],"tags":["svg","badge","classpath","io-exception"],"backgroundTag":"file-read-failed","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"}