Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Null Annotations / EEA

Sorry, Jan for not responding sooner. I wasn't subscribed to jdt-dev.

Work on null analysis in JDT has slowed down, partly because most of it is pretty stable, partly for lack of energy / people (some call it "resources").

Still you might be interested in one particular option that was added recently:
https://www.eclipse.org/eclipse/news/4.21/jdt.php#external_annotations_all_locations :)

I readily admit, that the set of annotations supported is not "complete" in several senses. Yet, supporting a new annotation is one of the heavy weight options of improving the tool.

Example: For some time we discussed another addition: @LazyNonNull. I was convinced of its benefit, because it addresses a fundamental problem regarding Object initialization. Just from mixed feedback I wasn't sure it would really carry its own weight. Still that annotation (or smth similar) would have been my next candidate.

Regarding @PolyNull I personally am less sure. Is it just an issue of retrofitting existing API into a null-annotated world, or is there an intrinsic design problem behind it, that doesn't have a satisfactory solution with the existing annotations?

If I were a frequent user of methods like Optional.orElse (which I'm not), I'd probably annotate argument and return as @NonNull. With this I would forgo the option to invoke it with a null argument, perhaps I would have to code differently in some few situations, but then everything could be checked in a suitable & safe way, no?

If you still think, something like @PolyNull should be the next addition to this tool, feel free to file an enhancement request in bugzilla (and post the link here for reference). That request would first need some backing by other users. If during that discussion some volunteer comes forward, I would be more than happy to guide him/her to the suitable code locations for implementation this feature.

best,
Stephan


From: "Jan N. Klug via jdt-dev" <jdt-dev@xxxxxxxxxxx>
Date: 17/07/2021 11:26 PM
Subject: [jdt-dev] Null Annotations / EEA
--------------------------------------------------------------------------------



Good evening,

you may know that there is a project named LastNPE that provides EEA for a bunch of libraries.

Recently a discussion was brought up how to correctly model the annotations for methods like Optional.orElse or Map.computeIfAbsent

In both cases we need to make the return value @Nullable, because the argument is allowed to be null and in that case the return value is also null. However this creates the need for a lot of unnecessary null-checks, if the value is guaranteed to be non-null, e.g. if used like Map.computeIfAbsent(key, k -> new Foo()).

So what we would need to have is something to express „same nullness like argument“ (like @PolyNull in checkerframework) or the option to have two annotations, one for a @Nullable argument and one for a @NonNull argument. Both need support in the compiler.

That‘s why I‘m writing here. I couldn’t find a discussion for that. WDYT?

Jan (GitHub: J-N-K)

_______________________________________________
jdt-dev mailing list
jdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jdt-dev <https://www.eclipse.org/mailman/listinfo/jdt-dev>






Back to the top