{"record":{"id":"6ed28f97dc8103f1","repo":"SonarSource/sonarqube","slug":"could-not-validate-gitlab-token-got-an-unexpected","errorCode":null,"errorMessage":"Could not validate GitLab token. Got an unexpected answer.","messagePattern":"Could not validate GitLab token\\. Got an unexpected answer\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabApplicationClient.java","lineNumber":144,"sourceCode":"    String url = format(\"%s/user\", gitlabUrl);\n\n    LOG.debug(\"get current user : [{}]\", url);\n    Request.Builder builder = new Request.Builder()\n      .addHeader(PRIVATE_TOKEN, personalAccessToken)\n      .url(url)\n      .get();\n\n    Request request = builder.build();\n\n    String errorMessage = \"Could not validate GitLab token. Got an unexpected answer.\";\n    try (Response response = client.newCall(request).execute()) {\n      checkResponseIsSuccessful(response, errorMessage);\n      return GsonUser.parse(response.body().string());\n    } catch (JsonSyntaxException e) {\n      throw new IllegalArgumentException(\"Could not parse GitLab answer to verify token. Got a non-json payload as result.\");\n    } catch (IOException e) {\n      logException(url, e);\n      throw new IllegalArgumentException(errorMessage);\n    }\n  }\n\n  public GsonPersonalAccessTokenInfo getPersonalAccessTokenInfo(String gitlabUrl, String personalAccessToken) {\n    String url = format(\"%s/personal_access_tokens/self\", gitlabUrl);\n\n    LOG.debug(\"get personal access token info : [{}]\", url);\n    Request request = new Request.Builder()\n      .addHeader(PRIVATE_TOKEN, personalAccessToken)\n      .url(url)\n      .get()\n      .build();\n\n    String errorMessage = \"Could not validate GitLab token scopes. Got an unexpected answer.\";\n    try (Response response = client.newCall(request).execute()) {\n      checkResponseIsSuccessful(response, errorMessage);\n      return GsonPersonalAccessTokenInfo.parseOne(response.body().string());\n    } catch (JsonSyntaxException e) {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/gitlab/GitlabApplicationClient.java#L126-L162","documentation":"Thrown by GitlabApplicationClient.checkToken when the HTTP request to the GitLab /user endpoint fails with an IOException (network-level failure). Note this same message is also used by checkResponseIsSuccessful for non-successful HTTP statuses, and the IOException is logged before rethrowing.","triggerScenarios":"checkToken: client.newCall(request).execute() or response.body().string() throws IOException — host unreachable, DNS failure, TLS handshake error, timeout, or connection reset.","commonSituations":"SonarQube server cannot reach GitLab; self-signed certificate not trusted; gitlabUrl mistyped; GitLab API outage.","solutions":["Test connectivity from the SonarQube host: curl -H 'PRIVATE-TOKEN: <token>' <gitlabUrl>/user","If the token is wrong/revoked you may instead see this via a non-2xx status: verify the token has 'api' scope and is still valid","Add the GitLab TLS certificate to the JVM truststore and fix the gitlabUrl"],"exampleFix":"// before: token without 'api' scope -> 403 handled as failure\n// after: create a GitLab PAT with scope 'api' and re-enter it in ALM settings","handlingStrategy":"validation","validationCode":"curl -sS -o /dev/null -w '%{http_code}' -H \"PRIVATE-TOKEN: $TOKEN\" \"$GITLAB_URL/api/v4/user\"  # expect 200 before configuring","typeGuard":null,"tryCatchPattern":"try { gitlabClient.checkToken(url, token); } catch (IllegalArgumentException e) { log.error(\"Token/network validation failed: verify token validity, 'api' scope, and connectivity\", e); }","preventionTips":["Create the personal access token with the 'api' scope and check it is not expired","Confirm network reachability and TLS trust from the SonarQube host","Re-check the token after rotation or user deactivation in GitLab"],"tags":["gitlab","network","token","http-request"],"backgroundTag":"http-request-failed","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"}