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

AssertionError in ResponseSubscribers$HttpResponseInputStream

XMLWordPrintable

    • b10
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When calling jdk.internal.net.http.ResponseSubscribers$HttpResponseInputStream.read(byte[], int, int) with len = 0 an assertion fails because it requires len to be positive

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Make sure to apply the -ea option to enable assertions
      2. Create a HttpClient
      3. send a request using BodyHandlers.ofInputStream() as the responseBodyHandler
      4. Get the body from the response and call read(byte[], int, int) with len = 0

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The read method should just return without doing anything as stated by the JavaDoc on InputStream.read(byte[], int, int): "If len is zero, then no bytes are read and 0 is returned"
      ACTUAL -
      Exception in thread "main" java.lang.AssertionError
      at java.net.http/jdk.internal.net.http.ResponseSubscribers$HttpResponseInputStream.read(ResponseSubscribers.java:449)
      at Main.main(Main.java:11)


      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.net.URI;
      import java.net.http.HttpClient;
      import java.net.http.HttpRequest;
      import java.net.http.HttpResponse.BodyHandlers;

      public class Main {

      public static void main (String[] args) {
      try {
      HttpClient.newHttpClient().send(HttpRequest.newBuilder(URI.create("https://www.example.com/")).build(), BodyHandlers.ofInputStream()).body().read(new byte[16], 0, 0);
      } catch (IOException | InterruptedException e) {
      e.printStackTrace();
      }
      }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            pconcannon Patrick Concannon (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: