{"record":{"id":"5bfc2762dfe70185","repo":"SonarSource/sonarqube","slug":"syntax","errorCode":"SYNTAX","errorMessage":"Failed to read SARIF report at '%s': %s","messagePattern":"Failed to read SARIF report at '(.+?)': (.+?)","errorType":"exception","errorClass":"SarifDeserializationException","httpStatus":null,"severity":"error","filePath":"sonar-core/src/main/java/org/sonar/core/sarif/SarifSerializerImpl.java","lineNumber":88,"sourceCode":"  @Override\n  public SarifSchema210 deserialize(Path reportPath) {\n    try {\n      return mapper\n        .enable(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION)\n        .addHandler(new DeserializationProblemHandler() {\n          @Override\n          public Object handleInstantiationProblem(DeserializationContext ctxt, Class<?> instClass, Object argument, Throwable t) throws IOException {\n            if (!instClass.equals(SarifSchema210.Version.class)) {\n              return NOT_HANDLED;\n            }\n            throw new UnsupportedSarifVersionException(format(UNSUPPORTED_VERSION_MESSAGE_TEMPLATE, argument), t);\n          }\n        })\n        .readValue(reportPath.toFile(), SarifSchema210.class);\n    } catch (UnsupportedSarifVersionException e) {\n      throw new SarifDeserializationException(Category.MAPPING, e.getMessage(), e);\n    } catch (JsonParseException e) {\n      throw new SarifDeserializationException(Category.SYNTAX, format(SARIF_REPORT_ERROR, reportPath, e.getMessage()), e);\n    } catch (JsonMappingException e) {\n      if (e.getMessage() != null && (e.getMessage().contains(\"out of range\") || e.getMessage().contains(\"overflow\"))) {\n        throw new SarifDeserializationException(Category.VALUE, format(SARIF_REPORT_ERROR, reportPath, e.getMessage()), e);\n      }\n      throw new SarifDeserializationException(Category.MAPPING, format(SARIF_REPORT_ERROR, reportPath, e.getMessage()), e);\n    } catch (FileNotFoundException e) {\n      throw new SarifDeserializationException(Category.FILE_NOT_FOUND, format(SARIF_REPORT_ERROR, reportPath, e.getMessage()), e);\n    } catch (IOException e) {\n      throw new IllegalStateException(format(SARIF_REPORT_ERROR, reportPath, e.getMessage()), e);\n    }\n  }\n\n  private static class UnsupportedSarifVersionException extends IOException {\n\n    public UnsupportedSarifVersionException(String message, Throwable t) {\n      super(message, t);\n    }\n  }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-core/src/main/java/org/sonar/core/sarif/SarifSerializerImpl.java#L70-L106","documentation":"SonarQube's SARIF importer wraps Jackson's JsonParseException into SarifDeserializationException with Category.SYNTAX when the report file at reportPath is not valid JSON (malformed syntax: stray characters, truncation, truncated/unterminated strings or brackets). The message 'Failed to read SARIF report at %s: %s' embeds the path and Jackson's own parse-error description (often with line/column). It is thrown from SarifSerializerImpl.deserialize so callers can classify import failures by category.","triggerScenarios":"Calling SarifSerializer.deserialize(Path) (directly or via SARIF report import in SonarQube) on a file whose content is not syntactically valid JSON — e.g. an HTML error page saved as .sarif, a truncated download, a file containing BOM/prose, or an empty file that Jackson reports as 'No content to map due to end-of-input'.","commonSituations":"CI artifact upload corrupted or truncated the SARIF file; a tool wrote a non-JSON log to the SARIF path; user pointed sonar.sarifReportPaths at the wrong file; file downloaded via HTTP where the server returned an error page with 200; file encoding issues (UTF-16 SARIF read as UTF-8).","solutions":["Open the report at the path in the message and validate it with a JSON linter/parser (e.g. `jq . report.sarif`) to find the exact line/column Jackson reports","Re-export or re-download the SARIF report from the producing tool; verify the download completed (compare file size/checksum)","Verify the path passed to deserialize()/sonar.sarifReportPaths points to the actual SARIF JSON file, not a log, HTML page, or directory listing","Ensure the file is UTF-8 encoded without BOM and was not truncated by the transfer"],"exampleFix":"// before\nSarifSchema210 sarif = sarifSerializer.deserialize(reportPath); // throws SYNTAX on corrupt file\n// after\nbyte[] bytes = java.nio.file.Files.readAllBytes(reportPath);\ntry (var parser = new com.fasterxml.jackson.core.JsonFactory().createParser(bytes)) {\n  while (parser.nextToken() != null) { } // fail fast with Jackson's line/column if invalid\n}\nSarifSchema210 sarif = sarifSerializer.deserialize(reportPath);","handlingStrategy":"validation","validationCode":"boolean isValidJsonFile(Path p) throws IOException {\n  if (!Files.isRegularFile(p)) return false;\n  try (com.fasterxml.jackson.core.JsonParser parser = new com.fasterxml.jackson.core.JsonFactory()\n      .createParser(Files.newBufferedReader(p, StandardCharsets.UTF_8))) {\n    while (parser.nextToken() != null) { }\n    return true;\n  } catch (com.fasterxml.jackson.core.JsonParseException e) {\n    return false;\n  }\n}","typeGuard":"boolean isReadableSarif(Path p) {\n  return Files.isRegularFile(p) && Files.size(p) > 0\n    && p.getFileName().toString().matches(\"(?i).*\\\\.sarif(json)?$\");\n}","tryCatchPattern":"try {\n  SarifSchema210 sarif = serializer.deserialize(reportPath);\n} catch (SarifDeserializationException e) {\n  if (e.getCategory() == Category.SYNTAX) {\n    LOG.error(\"SARIF report is not valid JSON: {}\", reportPath); // skip or re-export\n  } else throw e;\n}","preventionTips":["Validate generated SARIF output with the official SARIF 2.1.0 schema in your pipeline before import","Validate the JSON parses (jq or a JSON parser) as part of report generation","Avoid hand-editing SARIF files; always re-export from the producing tool","Check for truncated transfers by comparing file size/checksum after download"],"tags":["sarif","jackson","json-parse","import"],"backgroundTag":"json-parse-error","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"}