Skip to content

Conversation

marcphilipp
Copy link
Member

Overview

In order to check nullability annotations on generics in the build.


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


Definition of Done

@marcphilipp marcphilipp self-assigned this Jun 4, 2025
@marcphilipp marcphilipp force-pushed the marc/enable-jspecify-mode branch from 4d67c0e to dc41153 Compare June 4, 2025 16:50
Comment on lines +229 to 230
@Nullable
T proceed() throws Throwable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense to force all Invocation implementations to return @Nullable value?
Would it be better to keep an older Invocation<T extends @Nullable Object> approach so every implementation declares if it really wants to produce nullable value or not?

* @see #forJavaUtilLogging(Level)
*/
public static LoggingListener forBiConsumer(BiConsumer<Throwable, Supplier<String>> logger) {
public static LoggingListener forBiConsumer(BiConsumer<@Nullable Throwable, Supplier<String>> logger) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most of the cases, the proper signature for Function-receiving methods is as follows:

Suggested change
public static LoggingListener forBiConsumer(BiConsumer<@Nullable Throwable, Supplier<String>> logger) {
public static LoggingListener forBiConsumer(BiConsumer<? super @Nullable Throwable, ? super Supplier<String>> logger) {

That would allow users to pass even something that implements BiConsumer<@Nullable Object, @Nullable Object>.

Unfortunately, Java uses use-site variance, so effectively it requires users to add super and extends for almost every method that uses generic parameters.

abstract void invokeMethod();

abstract <T> T invokeConstructor(Constructor<T> constructor, @Nullable Object outerInstance);
abstract <T> @Nullable T invokeConstructor(Constructor<T> constructor, @Nullable Object outerInstance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not sound right for invokeConstructor to return null. Does it mean the null signals the failure?

@marcphilipp
Copy link
Member Author

@vlsi Thanks for your feedback! I have since talked to @sdeleuze who told me that NullAway's JSpecify mode currently only works properly with JDK 24 because some compiler fixes haven't yet been backported to JDK 21.

@marcphilipp
Copy link
Member Author

Superseded by #4628

@marcphilipp marcphilipp closed this Jun 5, 2025
@marcphilipp marcphilipp deleted the marc/enable-jspecify-mode branch October 17, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants