Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8368528

HttpClient.Builder.connectTimeout should accept arbitrarily large values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 25
    • core-libs

      If configured with a sufficiently big timeout, HttpClient will throw an exception when sending a request. For instance,

      // var SUFFICIENTLY_BIG_DURATION = Duration.ofSeconds(Long.MAX_VALUE, 999_999_999); // (1)
      // var SUFFICIENTLY_BIG_DURATION = Duration.between(Instant.now(), Instant.MAX); // (2)
              var SUFFICIENTLY_BIG_DURATION = Duration.ofMillis(Long.MAX_VALUE); // (3)
              try (var client = HttpClient.newBuilder()
                      .followRedirects(HttpClient.Redirect.ALWAYS)
                      .connectTimeout(SUFFICIENTLY_BIG_DURATION)
                      .build()) {
                  var request = HttpRequest.newBuilder(URI.create("https://dev.java"))
                          .header("Accept", "text/html")
                          .GET()
                          .build();
                  var response = client.send(request, HttpResponse.BodyHandlers.ofString());
                  System.out.println(response.body());
              }

      Note that (2) and (3) result in a stacktrace which differs from that of (1).

            vyazici Volkan Yazici
            prappo Pavel Rappo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: