Skip to content

Replace @Nullable with @UnknownNullability on MinecraftClient.player #4229

@Earthcomputer

Description

@Earthcomputer

(Reminder: Loom now has the ability to apply annotation changes from mapping sets such as yarn.)

I want to start a discussion on replacing Mojang's use of the @Nullable annotation with @UnknownNullability when the nullness of something frequently does not need to be checked. Here's what the @Nullable docs have to say about this situation:

By convention, this annotation applied only when the value should always be checked against null because the developer could do nothing to prevent null from happening. Otherwise, too eager Nullable usage could lead to too many false positives from static analysis tools.

For example, Map.get(Object key) should not be annotated Nullable because someone may have put not-null value in the map by this key and is expecting to find this value there ever since. It could be annotated as UnknownNullability or left unannotated.

On the other hand, the Reference.get() should be annotated Nullable because it returns null if object got collected which can happen at any time completely unexpectedly.

In our case, @UnknownNullability makes sense not only from a documentation perspective, but also to override the @FieldsAreNonnullByDefault annotation.

This issue applies to fields such as MinecraftClient.player, MinecraftClient.world, and others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions