Support jSpecify annotations

Hello folks,

I’ve seen that jSpecify is becoming a standard in Java to flag nullable vs. non nullable code.

I was wondering if we could get some support of it in Scala code when integrating with Java libraries to detect possible NPE at compile time.

I haven’t thought about it much for now, I’m looking for people’s feedback on this.

I guess this could be enabled with a specific compilation flag to raise warnings/errors. And/or implemented as part of “explicit nulls” feature to infer types as X | Null for nullable code according to jSpecify annotations.

FWIW, Kotlin has implemented some support for it and raise errors by default:

As of version 2.1.0, the Kotlin compiler emits errors by default for problems found using JSpecify nullness. To change those to warnings, pass the [email protected]:warn flag.

2 Likes

@NonNull is supported with -Yexplicit-nulls already.

@Nullable is in a PR: Consider nullable annotations in explicit nulls by HarrisL2 · Pull Request #21953 · scala/scala3 · GitHub

1 Like

Oh, great, I had not find any mention of it when searching for “jSpecify Scala". I’ll try to come up with a documentation PR in both jSpecify documentation and Scala’s one I guess then.

Do you know if @NullMarked (and its opposite) supported?

It is not.