You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using a method reference with lambda, a @Nonnull warning will be prompted #4451
Quick heads-up first: this isn't really about method references. It's the annotation-based null analysis kicking in. If you swap Class::getXxxx for a plain lambda like x -> x.getXxxx(), you get the exact same warning — the squiggle just happens to land on the Comparator.comparing(...) call, which visually overlaps the method reference.
What's going on under the hood: the null analysis is done by Eclipse JDT (ecj), vscode-java just turns it on. The JDK standard library (Comparator, Function, and your own getter) doesn't carry any nullness annotations, so once your code sits in a nonnull-by-default context, the analyzer treats those as "null-unknown" and warns that they might not be @NonNull. It simply has no way to know that e.g. Comparator.comparing never returns null, because nothing tells it so.
That's also why it only shows up when (a) null analysis is enabled and (b) there's a @NonNull target around the call. Drop the nonnull-by-default and it goes quiet.
A couple of options if it's getting in your way:
If you don't really need null analysis, set java.compile.nullAnalysis.mode to disabled.
Activity
wenytang-ms commentedon Jul 3, 2026
Hey, thanks for the report
Quick heads-up first: this isn't really about method references. It's the annotation-based null analysis kicking in. If you swap
Class::getXxxxfor a plain lambda likex -> x.getXxxx(), you get the exact same warning — the squiggle just happens to land on theComparator.comparing(...)call, which visually overlaps the method reference.What's going on under the hood: the null analysis is done by Eclipse JDT (ecj), vscode-java just turns it on. The JDK standard library (
Comparator,Function, and your own getter) doesn't carry any nullness annotations, so once your code sits in a nonnull-by-default context, the analyzer treats those as "null-unknown" and warns that they might not be@NonNull. It simply has no way to know that e.g.Comparator.comparingnever returns null, because nothing tells it so.That's also why it only shows up when (a) null analysis is enabled and (b) there's a
@NonNulltarget around the call. Drop the nonnull-by-default and it goes quiet.A couple of options if it's getting in your way:
java.compile.nullAnalysis.modetodisabled.Linking this to #2731 since it's the same underlying thing (recognizing the non-nullness of standard-library methods).