RFR: 8373661: Add edge case tests for Objects.requireNonNull methods
eunbin son
duke at openjdk.org
Thu Dec 18 11:54:41 UTC 2025
On Tue, 16 Dec 2025 22:14:27 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> ## Summary
>> Adds comprehensive edge case tests for `Objects.requireNonNull`,
>> `requireNonNullElse`, and `requireNonNullElseGet` methods to improve
>> test coverage.
>>
>> ## Problem
>> The current test suite for `Objects.requireNonNull` methods covers
>> basic cases but lacks edge case coverage.
>>
>> ## Solution
>> This PR adds tests for the following edge cases:
>> - requireNonNull with null Supplier parameter
>> - requireNonNull with Supplier that throws exception
>> - requireNonNullElse with both arguments null
>> - requireNonNullElseGet with null supplier
>> - requireNonNullElseGet with supplier returning null
>>
>> ## Issue
>> Fixes JDK-8373661
>>
>> **JBS Issue Link**: https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8373661
>>
>> ## Type of Change
>> - [x] Test addition/modification
>> - [ ] Bug fix
>> - [ ] New feature
>> - [ ] Documentation improvement
>> - [ ] Refactoring
>>
>> ## Testing
>>
>> make test TEST="jtreg:test/jdk/java/util/Objects"
>
> The new tests scope is good.
> The current standard for tests is JUnit and it would be better to convert the test to JUnit before adding new tests.
Thank you for the detailed feedback, @RogerRiggs and @liach!
I've addressed the following:
- [x] Expanded wildcard imports to individual imports (as requested by @RogerRiggs)
- [x] Simplified test messages to just identify the test (as both reviewers suggested)
- [x] Used Assertions.fail() where appropriate (as suggested by @RogerRiggs)
- [x] Kept assertTrue/assertFalse for isNull API tests (as @liach correctly noted)
- [x] Simplified assertThrows message argument to just testFuncName (as suggested by @RogerRiggs)
Regarding wildcard imports and Assertions.fail vs exceptions: I've made the changes as requested, but I understand from @liach's comment that these are acceptable either way. I've followed @RogerRiggs's preferences for consistency.
The changes have been pushed. Please review again.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28845#issuecomment-3669913387
More information about the core-libs-dev
mailing list