Nullable reference types (NRT) are enabled by default for this project. Some files, originally authored prior to enabling NRT, are marked #nullable disable to disable null checking.
The usage of the null-forgiving operator is generally discouraged except for test code and special cases described below. If eliding the nullability at runtime is unavoidable, use Debug.Assert() instead, or the .AsNonNull() extension method provided by framework.
Dependency injection considerations
The compiler will complain if a Resolved field of a non-nullable reference type is not initialized in the constructor. However, the field is non-nullable during the lifetime of the Drawable, after dependency injection has taken place.
We use NRT for a such field, and initialize it by null! (null-forgiving operator applied to null).
However, that pattern introduces nullability false-positives. For example, in a Dispose() method, a Resolved field may be null because the Drawable can be disposed after failing to load.
In that case, use x.IsNotNull() from osu.Framework.Extensions.ObjectExtensions to suppress warning:
For nullable/optional dependencies, Resolved automatically sets CanBeNull = true for a nullable reference type.
The same applies to BDL methods: