@NotNull
  public JiraRemoteApi discoverApiVersion() throws Exception {
    if (LEGACY_API_ONLY) {
      LOG.info("Intentionally using only legacy JIRA API");
      return createLegacyApi();
    }

    String responseBody;
    GetMethod method = new GetMethod(getRestUrl("serverInfo"));
    try {
      responseBody = executeMethod(method);
    }
    catch (Exception e) {
      // probably JIRA version prior 4.2
      // It's not safe to call HttpMethod.getStatusCode() directly, because it will throw NPE
      // if response was not received (connection lost etc.) and hasBeenUsed()/isRequestSent() are
      // not the way to check it safely.
      StatusLine status = method.getStatusLine();
      if (status != null && status.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        return createLegacyApi();
      }
      else {
        throw e;
      }
    }
    JsonObject serverInfo = GSON.fromJson(responseBody, JsonObject.class);
    // when JIRA 4.x support will be dropped 'versionNumber' array in response
    // may be used instead version string parsing
    myJiraVersion = serverInfo.get("version").getAsString();
    myInCloud = isHostedInCloud(serverInfo);
    LOG.info("JIRA version (from serverInfo): " + getPresentableVersion());
    if (isInCloud()) {
      LOG.info("Connecting to JIRA Cloud. Cookie authentication is enabled unless 'tasks.jira.basic.auth.only' VM flag is used.");
    }
    JiraRestApi restApi = JiraRestApi.fromJiraVersion(myJiraVersion, this);
    if (restApi == null) {
      throw new Exception(TaskBundle.message("jira.failure.no.REST"));
    }
    return restApi;
  }
@NotNull
  public JiraRemoteApi discoverApiVersion()