Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Question regarding NullMarked/NullUnmarked classes, interfaces, etc.implemented/extended into others.

48 views
Skip to first unread message

Andreas Schmidt

unread,
Mar 17, 2025, 9:48:49 PMMar 17
to jspecify...@googlegroups.com
Dear JSpecify team,
Recently have I started to implement JSpecify within my project.
During this process have I come to a situation that raised a question I couldn’t answer by reading the Javadoc of the annotation or reading your FAQ page.
This question is, how NullMarked or NullUnmarked classes, interfaces, etc. are handled/understood, if said class, interface, etc. is implemented/extended into another, which also is marked as NullMarked/NullUnmarked.
More specifically, imagine the following situation:
  • Interface MyInterfaceA is containing «String getSomeString()», «Integer getSomeInteger()» and «Boolean getSomeBoolean()». It is marked with NullMarked on the class level.
  • Interface MyInterfaceB<T> is extending MyInterfaceA and adds «T getGeneric()». It is annotated with NullUnmarked also on the class level.
Would in such a situation the methods of MyInterfaceA still be considered as NonNull through its NullMarked annotation, or would the NullUnmarked annotation take priority here and force them to be considered Nullable?
It’s something I believe should be answered somewhere within your documentation. If already the case should it be mentioned more prominently as I haven’t seen nor found it anywhere during my search.
I hope for a quick and clear reply and wish you a nice day.
 
Sincerely,
Andreas Schmidt

Chris Povirk

unread,
Mar 18, 2025, 12:08:31 PMMar 18
to Andreas Schmidt, jspecify...@googlegroups.com
Hi, Andreas,

Thanks for the question.

The idea is that a method is null-marked or not based on where it's declared. Thus, if you're calling getSomeString(), getSomeInteger(), or getSomeBoolean(), even if you're calling them on an instance of MyInterfaceB, they still have non-null return types because they are declared inside the null-marked InterfaceA.

This is technically covered by the phrase "code transitively enclosed within it" in the Javadoc for NullMarked, but that's too subtle for a question that I think we've already been asked before. (And it might not even be the best technical way to describe it :)) I've filed jspecify#728 for us to document this better somewhere.

Regards,
Chris
Reply all
Reply to author
Forward
0 new messages