RFR: 8373660: Add explicit null check in DataOutputStream.writeBytes
Attila Szegedi
attila at openjdk.org
Sun Jan 11 14:51:52 UTC 2026
On Wed, 17 Dec 2025 12:56:14 GMT, Eunbin Son <duke at openjdk.org> wrote:
> ## Summary
>
> Add explicit null check using `Objects.requireNonNull` in
> `DataOutputStream.writeBytes(String s)` to provide a clearer error message
> and make the API contract explicit.
>
> ## Problem
>
> The `writeBytes` method currently throws a `NullPointerException` when
> `null` is passed, but the error message may not be clear in all contexts.
> While JDK 14+ provides helpful NullPointerException messages through
> JEP 358 (Helpful NullPointerExceptions), adding an explicit null check
> using `Objects.requireNonNull` makes the API contract more explicit and
> provides consistent error messaging across different JDK versions.
>
> ## Solution
>
> Added `Objects.requireNonNull(s, "s")` at the beginning of the
> `writeBytes(String s)` method. This ensures:
> - A clear error message ("s") is provided when null is passed
> - The API contract explicitly states that null is not allowed
> - The method fails fast with a descriptive exception
>
> ## Issue
> Fixes JDK-8373660
>
> **JBS Issue Link**: https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8373660
>
>
> ## Type of Change
> - [x] Test addition/modification
> - [x] Bug fix
> - [ ] New feature
> - [ ] Documentation improvement
> - [ ] Refactoring
>
> ## Testing
>
> A new JUnit test has been added to verify the null check behavior:
>
>
> # Run the specific JUnit test file
> make test TEST="jtreg:test/jdk/java/io/DataOutputStream/DataOutputStreamTest.java"
>
> # Or run all tests in the DataOutputStream directory
> make test TEST="jtreg:test/jdk/java/io/DataOutputStream"
At least [this one comment](https://github.com/openjdk/jdk/pull/28869#issuecomment-3669945336) but possibly more of them are almost certainly LLM-generated.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28869#issuecomment-3734668245
More information about the core-libs-dev
mailing list