{"record":{"id":"26ab5aba75e27f15","repo":"SonarSource/sonarqube","slug":"could-not-parse-gitlab-answer-to-search-projects","errorCode":null,"errorMessage":"Could not parse GitLab answer to search projects. Got a non-json payload as result.","messagePattern":"Could not parse GitLab answer to search projects\\. 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":406,"sourceCode":"\n    LOG.debug(\"get projects : [{}]\", url);\n    Request request = new Request.Builder()\n      .addHeader(PRIVATE_TOKEN, personalAccessToken)\n      .url(url)\n      .get()\n      .build();\n\n    try (Response response = client.newCall(request).execute()) {\n      Headers headers = response.headers();\n      checkResponseIsSuccessful(response, \"Could not get projects from GitLab instance\");\n      List<Project> projectList = Project.parseJsonArray(response.body().string());\n      int returnedPageNumber = parseAndGetIntegerHeader(headers.get(\"X-Page\"));\n      int returnedPageSize = parseAndGetIntegerHeader(headers.get(\"X-Per-Page\"));\n      String xtotal = headers.get(\"X-Total\");\n      Integer totalProjects = Strings.isEmpty(xtotal) ? null : parseAndGetIntegerHeader(xtotal);\n      return new ProjectList(projectList, returnedPageNumber, returnedPageSize, totalProjects);\n    } catch (JsonSyntaxException e) {\n      throw new IllegalArgumentException(\"Could not parse GitLab answer to search projects. 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  private static int parseAndGetIntegerHeader(@Nullable String header) {\n    if (header == null) {\n      throw new IllegalArgumentException(\"Pagination data from GitLab response is missing\");\n    } else {\n      try {\n        return Integer.parseInt(header);\n      } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Could not parse pagination number\", e);\n      }\n    }\n  }\n","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabApplicationClient.java#L388-L424","documentation":"searchProjects queries the GitLab projects search endpoint, reads pagination headers (X-Page, X-Per-Page, X-Total) and parses the JSON project list. If the body fails Gson parsing, JsonSyntaxException is rethrown as this IllegalArgumentException. GitLab answered successfully but with a payload that is not the expected JSON array.","triggerScenarios":"Calling searchProjects(url, token, ...) (also exercised by fetchTotalCount) when the 2xx response body is HTML, empty, or otherwise non-JSON while paging through GitLab projects.","commonSituations":"Corporate proxy or SSO intercepts paginated project list requests and returns HTML; wrong GitLab URL; load balancer timeouts returning empty 200 bodies; GitLab maintenance pages served with success status.","solutions":["Validate the GitLab URL configuration reaches the GitLab API directly.","Trace-log the body (payload result) to identify what non-JSON content was returned.","Check intermediate proxies/load balancers for HTML injection into 2xx responses.","Retry the search; if intermittent, investigate GitLab instance health or rate-limiting intermediaries."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ProjectList list = client.searchProjects(url, token, query, page, size); } catch (IllegalArgumentException e) { /* retry once, then report config/network issue */ }","preventionTips":["Ensure the GitLab URL targets the authentic API (no rewriting intermediaries)","Monitor GitLab instance health; transient gateway pages can break paging","Capture response bodies via trace logs for diagnosis"],"tags":["gitlab","json-parsing","pagination","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"}