mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-22 01:17:38 +00:00
Switch the core-api to be non-null by default
We'll do this everywhere eventually, but much easier to do it incrementally: - Use checker framework to default all field/methods/parameters to @Nonnull. - Start using ErrorProne[1] and NullAway[2] to check for possible null pointer issues. I did look into using CheckerFramework, but it's much stricter (i.e. it's actually Correct). This is technically good, but is a much steeper migration path, which I'm not sure we're prepared for yet! [1]: https://github.com/google/error-prone [2]: https://github.com/uber/NullAway
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.core.util;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class Nullability {
|
||||
private Nullability() {
|
||||
}
|
||||
|
||||
/**
|
||||
* An alternative to {@link java.util.Objects#requireNonNull(Object)}, which should be interpreted as an assertion
|
||||
* ("this case should never happen") rather than an argument check.
|
||||
*
|
||||
* @param object The object to check, possibly {@literal null}.
|
||||
* @param <T> The type of the object to check
|
||||
* @return The checked value.
|
||||
*/
|
||||
public static <T> T assertNonNull(@Nullable T object) {
|
||||
if (object == null) throw new NullPointerException("Impossible: Should never be null");
|
||||
return object;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user