Hello all! I’m currently working on a PR to add jSpecify NullMarked support to scala. I’d like to see who actually runs into issues under explicit null with libraries giving them platform types even though those library authors fully documented their code with @NullMarked annotations.
This is an extension of a discussion from GitHub. I’ll copy my response for completeness:
Minecraft since 26.1 is now deobfuscated and that means it now preserves annotations, and mojang uses @NullMarked in basically every single package.
Let’s take for example in 26.1.2 Item#use.
Copy of its java signature for completeness:
public InteractionResult use(final Level level, final Player player, final InteractionHand hand)
It lives in a NullMarked package so languages like Kotlin, when your IDE autocompletes, will correctly override this as a completely non nullable method.
HOWEVER, in VSCode (or any editor using Metals), a scala project will instead give you this override signature:
override def use(level: (Level)?, player: (Player)?, hand: (InteractionHand)?): (InteractionResult)? = ???
this isn’t kotlin, so ? doesn’t mean “nullable” it means “flexible type” which is non denotable so this is just an error you have to fix. Ignoring the weird jank in flexible type overrides, it shouldn’t even be a flexible type. These should be non nullable!
The signature the compile should infer is this:
override def use(level: Level, player: Player, hand: InteractionHand): InteractionResult = ???
Of course scala doesn’t actually support @NullMarked so it sees only unannotated types, which mean platform types.
If anyone else has anything to add, please feel free to share! I’d really like to get some eyes on this PR considering it requires more effort than one would assume at a glance.