Class ProtocolPreconditions
java.lang.Object
nl.pim16aap2.lightkeeper.protocol.ProtocolPreconditions
Validation helpers for protocol command compact constructors.
Wire requests are deserialized straight into records, bypassing NullAway, so a malformed request can put
null/garbage into a non-@Nullable field. Validating in the compact constructor rejects such
input up front with a consistent IllegalArgumentException (which the dispatcher maps to
INVALID_ARGUMENT) instead of letting it fail deep inside a server handler with an opaque error.
Example:
public Command
{
ProtocolPreconditions.requireNonBlank(requestId, "requestId");
ProtocolPreconditions.requireNonNull(uuid, "uuid");
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublerequireFinite(double value, String name) Requires that a coordinate is a finite number (not NaN or infinite).static StringrequireNonBlank(@Nullable String value, String name) Requires that a string is neithernullnor blank.static intrequireNonNegative(int value, String name) Requires that an integer is not negative.static <T> TrequireNonNull(@Nullable T value, String name) Requires that a reference is non-null.
-
Method Details
-
requireNonBlank
Requires that a string is neithernullnor blank.- Parameters:
value- The value to check.name- Field name used in the failure message.- Returns:
- The validated value.
- Throws:
IllegalArgumentException- Whenvalueisnullor blank.
-
requireNonNull
Requires that a reference is non-null.- Type Parameters:
T- The value type.- Parameters:
value- The value to check.name- Field name used in the failure message.- Returns:
- The validated value.
- Throws:
IllegalArgumentException- Whenvalueisnull.
-
requireNonNegative
Requires that an integer is not negative.- Parameters:
value- The value to check.name- Field name used in the failure message.- Returns:
- The validated value.
- Throws:
IllegalArgumentException- Whenvalueis negative.
-
requireFinite
Requires that a coordinate is a finite number (not NaN or infinite).- Parameters:
value- The value to check.name- Field name used in the failure message.- Returns:
- The validated value.
- Throws:
IllegalArgumentException- Whenvalueis NaN or infinite.
-