RFR: 8334028: HttpClient: NPE thrown from assert statement

Daniel Fuchs dfuchs at openjdk.org
Tue Jun 11 14:44:33 UTC 2024


The `jdk.internal.http.common.Utils` class exposes methods that work on lists or arrays of byte buffers, and tell whether or how much remaining data is present in the buffers in the list/array. These methods currently throw `NullPointerException` if the given list/buffer is null.

This is not in itself an issue, except that these methods are often called in debug statements, or in assert statements, where `null` could be passed and `NullPointerException` are not expected and should not be thrown.

One such assert statement in `ResponseSubscribers` hid a bug where a `NullPointerException` that  should have been unconditionally thrown was in fact only thrown if asserts were enabled. The test that was supposed to verify that NPEs are thrown was passing because assert are always enabled by default when running tests.

The proposed change modifies these Utils methods to allow null parameter, returning false or 0 when a null list or array is given. It also fixes the code in ResponseSunscribers that was throwing from the assert to unconditionally check for nulls before the assertion.

-------------

Commit messages:
 - 8334028

Changes: https://git.openjdk.org/jdk/pull/19661/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19661&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8334028
  Stats: 22 lines in 3 files changed: 18 ins; 0 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/19661.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19661/head:pull/19661

PR: https://git.openjdk.org/jdk/pull/19661


More information about the net-dev mailing list