SonarSource/sonarqube · error · IllegalStateException

Failed to list all organizations accessible by user access t

Error message

Failed to list all organizations accessible by user access token on %s

What it means

listOrganizations fetches all GitHub organizations accessible by a user access token via the GitHub API. Any IOException during the HTTP exchange (connection failure, stream error) is wrapped in this IllegalStateException with the appUrl in the message. It indicates the request to enumerate orgs could not be completed at the transport level.

Source

Thrown at server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java:278

      Organizations organizations = new Organizations();
      GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format("/user/installations?page=%s&per_page=%s", page, pageSize));
      Optional<GsonInstallations> gsonInstallations = response.getContent().map(content -> GSON.fromJson(content, GsonInstallations.class));

      if (!gsonInstallations.isPresent()) {
        return organizations;
      }

      organizations.setTotal(gsonInstallations.get().getTotalCount());
      if (gsonInstallations.get().getInstallations() != null) {
        organizations.setOrganizations(gsonInstallations.get().getInstallations().stream()
          .map(gsonInstallation -> new Organization(gsonInstallation.getAccount().getId(), gsonInstallation.getAccount().getLogin(), null, null, null, null, null,
            gsonInstallation.getTargetType()))
          .toList());
      }

      return organizations;
    } catch (IOException e) {
      throw new IllegalStateException(format("Failed to list all organizations accessible by user access token on %s", appUrl), e);
    }
  }

  @Override
  public List<GithubAppInstallation> getWhitelistedGithubAppInstallations(GithubAppConfiguration githubAppConfiguration) {
    List<GithubBinding.GsonInstallation> gsonAppInstallations = fetchAppInstallationsFromGithub(githubAppConfiguration);
    Set<String> allowedOrganizations = gitHubSettings.getOrganizations();
    return convertToGithubAppInstallationAndFilterWhitelisted(gsonAppInstallations, allowedOrganizations);
  }

  private static List<GithubAppInstallation> convertToGithubAppInstallationAndFilterWhitelisted(List<GithubBinding.GsonInstallation> gsonAppInstallations,
    Set<String> allowedOrganizations) {
    return gsonAppInstallations.stream()
      .filter(appInstallation -> appInstallation.getAccount().getType().equalsIgnoreCase("Organization"))
      .map(GithubApplicationClientImpl::toGithubAppInstallation)
      .filter(appInstallation -> isOrganizationWhiteListed(allowedOrganizations, appInstallation.organizationName()))
      .toList();
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. From the SonarQube server, test connectivity to the appUrl (curl -v https://ghe.example.com/api/v3/user/orgs).
  2. Fix DNS/firewall/proxy so the server can reach the GitHub host on 443.
  3. Import the GHES TLS certificate into the JVM truststore if using self-signed/internal CA.
  4. Correct the appUrl configured in the DevOps platform integration settings.

Example fix

// before
client.listOrganizations("https://ghe.internal:8443", token);
// after
client.listOrganizations("https://ghe.internal", token); // reachable host, TLS terminated properly
Defensive patterns

Strategy: retry

Validate before calling

// preflight connectivity
Process p = Runtime.getRuntime().exec(new String[]{"curl","-sf","-o","/dev/null", appUrl + "/api/v3/rate_limit"});
if (p.waitFor() != 0) throw new IllegalStateException("GitHub unreachable: " + appUrl);

Try / catch

try { client.listOrganizations(appUrl, token); } catch (IllegalStateException e) { retryWithBackoff(3, e); }

Prevention

When it happens

Trigger: Calling listOrganizations(appUrl, accessToken) when the underlying HTTP call throws IOException — connection refused/timeout to appUrl, TLS handshake failure, or broken response stream.

Common situations: GitHub Enterprise URL unreachable from the SonarQube server (firewall/DNS), self-signed certificate not in the truststore, network outage, wrong port on the GHES host.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/038fb850a20d01f4. Report an issue: GitHub.