Hello Steffen,
I think this is fine. In the package summary of java.net.http, the last 
sentence says:

Unless otherwise stated, null parameter values will cause methods of all 
classes in this package to throw NullPointerException.

The method you mentioned in particular does mention NPE, but that clause aims 
to cover the edge cases where the headerMap contains null keys, null values, or 
one of its value List contains null.

I think a potential improvement here is to update the package summary to 
indicate NPE for any nested collection; this is what Class-File API does for 
java.lang.classfile and the subpackages.

Regards,
Chen Liang

________________________________
From: core-libs-dev <core-libs-dev-r...@openjdk.org> on behalf of Steffen 
Nießing <zuniq...@protonmail.com>
Sent: Monday, May 5, 2025 3:05 PM
To: core-libs-dev@openjdk.org <core-libs-dev@openjdk.org>
Subject: JavaDoc: NPE in java.net.http.HttpHeaders

Hello,

recently I've discovered that the JavaDoc of the instance methods of 
java.net.http.HttpHeaders lacks the throws declarations for 
NullPointerExceptions. The static creator method `of` contains such a 
declaration. So the snippet `HttpHeaders.of(null, null)` is documented to throw 
an NPE, while the snippet `HttpHeaders.of(Map.of(), (k, v) -> 
true).firstValue(null)` currently isn't.

I'd propose to add the missing JavaDoc throws declarations to the 
#allValues(String), #firstValueAsLong(String) and #firstValue(String) methods 
as they all can throw an NPE through `requireNonNull(name);` in the allValues 
method.

If there's interest in this change, I'd appreciate if anyone would like to 
sponsor me on this one.

Cheers,
Steffen

Reply via email to