{"record":{"id":"a5c8d426ee1ca95c","repo":"SonarSource/sonarqube","slug":"could-not-parse-gitlab-answer-to-retrieve-project","errorCode":null,"errorMessage":"Could not parse GitLab answer to retrieve project branches. Got a non-json payload as result.","messagePattern":"Could not parse GitLab answer to retrieve project branches\\. Got a non-json payload as result\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabApplicationClient.java","lineNumber":373,"sourceCode":"    }\n  }\n\n  public List<GitLabBranch> getBranches(String gitlabUrl, String pat, Long gitlabProjectId) {\n    String url = format(\"%s/projects/%s/repository/branches\", gitlabUrl, gitlabProjectId);\n    LOG.debug(\"get branches : [{}]\", url);\n    Request request = new Request.Builder()\n      .addHeader(PRIVATE_TOKEN, pat)\n      .get()\n      .url(url)\n      .build();\n\n    try (Response response = client.newCall(request).execute()) {\n      checkResponseIsSuccessful(response);\n      String body = response.body().string();\n      LOG.trace(\"loading branches payload result : [{}]\", body);\n      return Arrays.asList(new GsonBuilder().create().fromJson(body, GitLabBranch[].class));\n    } catch (JsonSyntaxException e) {\n      throw new IllegalArgumentException(\"Could not parse GitLab answer to retrieve project branches. Got a non-json payload as result.\");\n    } catch (IOException e) {\n      logException(url, e);\n      throw new IllegalStateException(e.getMessage(), e);\n    }\n  }\n\n  public ProjectList searchProjects(String gitlabUrl, String personalAccessToken, @Nullable String projectName,\n    @Nullable Integer pageNumber, @Nullable Integer pageSize) {\n    String url = format(\"%s/projects?archived=false&simple=true&membership=true%s%s%s\",\n      gitlabUrl,\n      projectName == null ? \"\" : (\"&search=\" + urlEncode(projectName)),\n      pageNumber == null ? \"\" : format(\"&page=%d\", pageNumber),\n      pageSize == null ? \"\" : format(\"&per_page=%d\", pageSize)\n    );\n\n    LOG.debug(\"get projects : [{}]\", url);\n    Request request = new Request.Builder()\n      .addHeader(PRIVATE_TOKEN, personalAccessToken)","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabApplicationClient.java#L355-L391","documentation":"getBranches calls the GitLab branches API and deserializes the body into a GitLabBranch[] with Gson. A 2xx response whose body is not valid JSON triggers JsonSyntaxException, rethrown as this IllegalArgumentException. The response came back 'successful' but its payload was not the expected JSON branch array.","triggerScenarios":"Calling getBranches(url, token, repoName) when the successful HTTP response body is HTML, empty, or otherwise unparseable instead of a JSON array of branches.","commonSituations":"Reverse proxy or WAF serving HTML maintenance pages with 200 status; wrong GitLab URL hitting an SSO login page; empty responses from misconfigured gateways; API path issues causing a rendered HTML 404 page to be served with 2xx after redirects.","solutions":["Verify the GitLab URL and that /api/v4 is reachable directly from the SonarQube server.","Log/inspect the actual response body (trace log 'loading branches payload result').","Check proxy/VPN/WAF configurations that may replace JSON with HTML.","Confirm the repository path is URL-encoded correctly so GitLab doesn't redirect to a web page."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { List<GitLabBranch> branches = client.getBranches(url, token, repo); } catch (IllegalArgumentException e) { LOG.warn(\"GitLab branches response was not JSON; check URL/proxy\", e); }","preventionTips":["URL-encode repository paths so GitLab doesn't redirect to HTML pages","Confirm /api/v4 reachability from the SonarQube server","Inspect trace logs for the raw body when errors occur"],"tags":["gitlab","json-parsing","branches","http-response"],"backgroundTag":"invalid-json-response","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"}