8334028: HttpClient: NPE thrown from assert statement
Reviewed-by: jpai
This commit is contained in:
parent
bd750b6b78
commit
81ca0ece2e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -356,6 +356,7 @@ public class ResponseSubscribers {
|
||||
// incoming buffers are allocated by http client internally,
|
||||
// and won't be used anywhere except this place.
|
||||
// So it's free simply to store them for further processing.
|
||||
Objects.requireNonNull(items); // ensure NPE is thrown before assert
|
||||
assert Utils.hasRemaining(items);
|
||||
received.addAll(items);
|
||||
}
|
||||
|
@ -746,6 +746,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static long remaining(ByteBuffer[] bufs) {
|
||||
if (bufs == null) return 0;
|
||||
long remain = 0;
|
||||
for (ByteBuffer buf : bufs) {
|
||||
remain += buf.remaining();
|
||||
@ -754,6 +755,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static boolean hasRemaining(List<ByteBuffer> bufs) {
|
||||
if (bufs == null) return false;
|
||||
for (ByteBuffer buf : bufs) {
|
||||
if (buf.hasRemaining())
|
||||
return true;
|
||||
@ -762,6 +764,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static boolean hasRemaining(ByteBuffer[] bufs) {
|
||||
if (bufs == null) return false;
|
||||
for (ByteBuffer buf : bufs) {
|
||||
if (buf.hasRemaining())
|
||||
return true;
|
||||
@ -770,6 +773,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static long remaining(List<ByteBuffer> bufs) {
|
||||
if (bufs == null) return 0L;
|
||||
long remain = 0;
|
||||
for (ByteBuffer buf : bufs) {
|
||||
remain += buf.remaining();
|
||||
@ -778,12 +782,14 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static long synchronizedRemaining(List<ByteBuffer> bufs) {
|
||||
if (bufs == null) return 0L;
|
||||
synchronized (bufs) {
|
||||
return remaining(bufs);
|
||||
}
|
||||
}
|
||||
|
||||
public static int remaining(List<ByteBuffer> bufs, int max) {
|
||||
public static long remaining(List<ByteBuffer> bufs, long max) {
|
||||
if (bufs == null) return 0;
|
||||
long remain = 0;
|
||||
for (ByteBuffer buf : bufs) {
|
||||
remain += buf.remaining();
|
||||
@ -794,7 +800,13 @@ public final class Utils {
|
||||
return (int) remain;
|
||||
}
|
||||
|
||||
public static int remaining(ByteBuffer[] refs, int max) {
|
||||
public static int remaining(List<ByteBuffer> bufs, int max) {
|
||||
// safe cast since max is an int
|
||||
return (int) remaining(bufs, (long) max);
|
||||
}
|
||||
|
||||
public static long remaining(ByteBuffer[] refs, long max) {
|
||||
if (refs == null) return 0;
|
||||
long remain = 0;
|
||||
for (ByteBuffer b : refs) {
|
||||
remain += b.remaining();
|
||||
@ -805,6 +817,11 @@ public final class Utils {
|
||||
return (int) remain;
|
||||
}
|
||||
|
||||
public static int remaining(ByteBuffer[] refs, int max) {
|
||||
// safe cast since max is an int
|
||||
return (int) remaining(refs, (long) max);
|
||||
}
|
||||
|
||||
public static void close(Closeable... closeables) {
|
||||
for (Closeable c : closeables) {
|
||||
try {
|
||||
|
@ -24,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @summary Basic test for the standard BodySubscribers default behavior
|
||||
* @bug 8225583
|
||||
* @bug 8225583 8334028
|
||||
* @run testng BodySubscribersTest
|
||||
*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user