Class ProtocolPreconditions

java.lang.Object
nl.pim16aap2.lightkeeper.protocol.ProtocolPreconditions

public final class ProtocolPreconditions extends Object
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 Details

    • requireNonBlank

      public static String requireNonBlank(@Nullable String value, String name)
      Requires that a string is neither null nor blank.
      Parameters:
      value - The value to check.
      name - Field name used in the failure message.
      Returns:
      The validated value.
      Throws:
      IllegalArgumentException - When value is null or blank.
    • requireNonNull

      public static <T> T requireNonNull(@Nullable T value, String name)
      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 - When value is null.
    • requireNonNegative

      public static int requireNonNegative(int value, String name)
      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 - When value is negative.
    • requireFinite

      public static double requireFinite(double value, String name)
      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 - When value is NaN or infinite.