Skip to content

Undetected @Nullable annotation in a method reference #1128

Closed

Description

@sdeleuze

With the JSpecify mode enabled, I have this interface:

public interface WebFluxConfigurer {

	default @Nullable WebSocketService getWebSocketService() {
		return null;
	}
}

And:

	public @Nullable WebSocketService getWebSocketService() {
		return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class);
	}

	private <T> @Nullable T createSingleBean(Function<WebFluxConfigurer, @Nullable T> factory, Class<T> beanType) {
		// ...
	}

I get the following IMO invalid error:

error: [NullAway] Cannot pass parameter of type Function<WebFluxConfigurer, WebSocketService>, as formal parameter has type Function<WebFluxConfigurer, @org.jspecify.annotations.Nullable T>, which has mismatched type parameter nullability

Activity

  1. changed the title [-]Undetected `@Nullable` annotation in a default method reference[/-] [+]Undetected `@Nullable` annotation in a method reference[/+] on Jan 13, 2025
  2. msridhar commented on Jan 31, 2025

    @msridhar
    Contributor

    I can reproduce this one. It's not about default methods, but the fact that the call is to a generic method and we don't handle the instances of @Nullable T correctly. This one will be a bit trickier to fix and will take a bit; probably best to just suppress for now.

  3. Stephan202 commented on Mar 22, 2025

    @Stephan202

    As suggested here by @msridhar, I'm sharing a test case that may be relevant to this issue:

    import static com.google.common.collect.ImmutableTable.toImmutableTable;
    
    import com.google.common.collect.ImmutableTable;
    import com.google.common.collect.Table;
    import com.google.common.collect.Tables;
    import java.util.stream.Stream;
    
    final class Test {
      ImmutableTable<String, String, String> m() {
        return Stream.of(Tables.immutableCell("foo", "bar", "baz"))
            .collect(
                toImmutableTable(
                    Table.Cell::getRowKey, Table.Cell::getColumnKey, Table.Cell::getValue));
      }
    }

    This triggers the following warnings:

    [WARNING] /path/to/Test.java:[15,17] [NullAway] referenced method returns @Nullable, but functional interface method java.util.function.Function.apply(T) returns @NonNull
        (see http://t.uber.com/nullaway )
    [WARNING] /path/to/Test.java:[15,40] [NullAway] referenced method returns @Nullable, but functional interface method java.util.function.Function.apply(T) returns @NonNull
        (see http://t.uber.com/nullaway )
    [WARNING] /path/to/Test.java:[15,66] [NullAway] referenced method returns @Nullable, but functional interface method java.util.function.Function.apply(T) returns @NonNull
        (see http://t.uber.com/nullaway )
    

    This happens only in JSpecify mode. The three flagged methods have had @ParametricNullness for four years, but the issue only reproduces with Guava 33.4.1-jre and above, likely because in that version @ElementTypesAreNonnullByDefault was replaced with @NullMarked.

  4. sdeleuze commented on Oct 1, 2025

    @sdeleuze
    Author

    This happens only in JSpecify mode.

    @msridhar Should probably be tagged with the jspecify label.

  5. added
    jspecify
    on Oct 1, 2025
  6. added a commit that references this issue on Jan 14, 2026
    d594809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    false positivejspecify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions