signalapp/Signal-Server · error · FieldValidationException

list size is [ ] but expected to be one of

Error message

list size is [%d] but expected to be one of %s

What it means

ExactlySizeFieldValidator.validateRepeatedField checks that a repeated proto field's element count is one of the permitted sizes. If the list size isn't permitted, it throws FieldValidationException with the actual and allowed sizes.

Solutions

  1. Check the allowed sizes from the error message and adjust the list to that length client-side
  2. If an empty list is the problem, ensure at least one element is added before sending
  3. Split batched data into multiple requests sized to permitted counts
  4. Validate list size in client code before building the request

Example fix

// before
request.addAllIdentifiers(Collections.emptyList());
// after
request.addIdentifiers(identifier); // exactly 1 element
Defensive patterns

Strategy: validation

Validate before calling

if (!permittedSizes.contains(items.size())) {
  throw new IllegalArgumentException("expected list size in " + permittedSizes + ", got " + items.size());
}

Try / catch

try {
  grpcStub.call(request);
} catch (StatusRuntimeException e) {
  if (e.getStatus().getCode() == Code.INVALID_ARGUMENT && e.getStatus().getDescription().contains("list size")) {
    // split or pad the batch to the permitted size and retry
  }
}

Prevention

When it happens

Trigger: gRPC requests carrying repeated fields (e.g. a list of device IDs, identifiers, or receipts) where the number of elements doesn't match the allowed counts — e.g. sending 0, 2, or 3 items where exactly 1 is required.

Common situations: Client sending an empty repeated field that must contain exactly one element; batching multiple items where the endpoint accepts one at a time; deduplication logic removing items and shrinking the list.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of signalapp/Signal-Server@100ab61c82 (2026-09-09). Data as JSON: /api/errors/473289746548ed01. Report an issue: GitHub.

Appendix: source

Thrown at service/src/main/java/org/whispersystems/textsecuregcm/grpc/validators/ExactlySizeFieldValidator.java:56

  @Override
  protected void validateStringValue(
      final Set<Integer> permittedSizes,
      final String fieldValue) throws FieldValidationException {
    if (permittedSizes.contains(fieldValue.length())) {
      return;
    }
    throw new FieldValidationException("string length is [%d] but expected to be one of %s".formatted(fieldValue.length(), permittedSizes));
  }

  @Override
  protected void validateRepeatedField(
      final Set<Integer> permittedSizes,
      final Descriptors.FieldDescriptor fd,
      final List<?> repeated) throws FieldValidationException {
    if (permittedSizes.contains(repeated.size())) {
      return;
    }
    throw new FieldValidationException("list size is [%d] but expected to be one of %s".formatted(repeated.size(), permittedSizes));
  }
}

View on GitHub (pinned to 100ab61c82)