Skip to content

Add computeIfAbsent variants for non-nullable types to stores #4760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marcphilipp
Copy link
Member

Since both ExtensionContext.Store and its backing
NamespaceAwareStore implementation allow storing null values, the
getOrComputeIfAbsent methods potentially returned null, even if
documented otherwise (in case of getOrComputeIfAbsent(Class) in
ExtensionContext.Store). Now that the API uses JSpecify's nullability
annotations, this became more apparent and also caused
Jupiter Extension implementations to have to deal with values being
potentially null despite their best intentions to only use
getOrComputeIfAbsent to access a certain key with a function that
never returned null. Therefore, this commit introduces null-safe
variants called computeIfAbsent that treat null as absent in
addition to the key not being present in the backing Map.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

Since both `ExtensionContext.Store` and its backing
`NamespaceAwareStore` implementation allow storing `null` values, the
`getOrComputeIfAbsent` methods potentially returned `null`, even if
documented otherwise (in case of `getOrComputeIfAbsent(Class)` in
`ExtensionContext.Store`). Now that the API uses JSpecify's nullability
annotations, this became more apparent and also caused
Jupiter `Extension` implementations to have to deal with values being
potentially `null` despite their best intentions to only use
`getOrComputeIfAbsent` to access a certain `key` with a function that
never returned `null`. Therefore, this commit introduces null-safe
variants called `computeIfAbsent` that treat `null` as absent in
addition to the key not being present in the backing `Map`.
@marcphilipp marcphilipp self-assigned this Jul 12, 2025
@marcphilipp marcphilipp added this to the 6.0.0-M2 milestone Jul 12, 2025
@marcphilipp marcphilipp changed the title Add computeIfAbsent variants to stores for non-nullable types Add computeIfAbsent variants for non-nullable types to stores Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant