refactor(ses): build not-null violations with SmithyValidationErrors (#6746)

The "Value at '<path>' failed to satisfy constraint: Member must not be
null" violation was still written by hand in 26 places across the SES
services and controllers. They now call
SmithyValidationErrors.notNullWithoutValue(path), keeping each site's
badRequest or validationError factory.

The length checks on websiteURL, additionalContactEmailAddresses and
certificateArn, which tested a lower and an upper bound side by side,
now go through SmithyValidationErrors.sizeOutOfRange.

The message text is unchanged, and the private wrappers stay because
their enum and other constraint callers still use them.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-27 12:03:18 -04:00
1 parent afdd4b46ec
commit 24d989cb07
12 files changed
+56 -49

No files matched your search

@@ -162,16 +162,18 @@ public class SesAccountService {
String useCaseDescription, List<String> additionalContacts) {
List<String> errors = new ArrayList<>();
if (mailType == null) {
errors.add(constraint("mailType", "Member must not be null"));
errors.add(SmithyValidationErrors.notNullWithoutValue("mailType"));
} else if (!MAIL_TYPES.contains(mailType)) {
errors.add(constraint("mailType", "Member must satisfy enum value set: [MARKETING, TRANSACTIONAL]"));
}
if (websiteUrl == null) {
errors.add(constraint("websiteURL", "Member must not be null"));
} else if (websiteUrl.isEmpty()) {
errors.add(constraint("websiteURL", "Member must have length greater than or equal to 1"));
} else if (websiteUrl.length() > WEBSITE_URL_MAX) {
errors.add(constraint("websiteURL", "Member must have length less than or equal to " + WEBSITE_URL_MAX));
errors.add(SmithyValidationErrors.notNullWithoutValue("websiteURL"));
} else {
String websiteUrlLength = SmithyValidationErrors.sizeOutOfRange("websiteURL", websiteUrl.length(),
1, WEBSITE_URL_MAX);
if (websiteUrlLength != null) {
errors.add(websiteUrlLength);
}
}
if (contactLanguage != null && !CONTACT_LANGUAGES.contains(contactLanguage)) {
errors.add(constraint("contactLanguage", "Member must satisfy enum value set: [EN, JA]"));
@@ -181,12 +183,10 @@ public class SesAccountService {
"Member must have length less than or equal to " + USE_CASE_DESCRIPTION_MAX));
}
if (additionalContacts != null) {
if (additionalContacts.isEmpty()) {
errors.add(constraint("additionalContactEmailAddresses",
"Member must have length greater than or equal to 1"));
} else if (additionalContacts.size() > CONTACTS_MAX) {
errors.add(constraint("additionalContactEmailAddresses",
"Member must have length less than or equal to " + CONTACTS_MAX));
String contactsSize = SmithyValidationErrors.sizeOutOfRange("additionalContactEmailAddresses",
additionalContacts.size(), 1, CONTACTS_MAX);
if (contactsSize != null) {
errors.add(contactsSize);
}
for (String contact : additionalContacts) {
if (contact == null || contact.length() < CONTACT_MIN || contact.length() > CONTACT_MAX
@@ -280,8 +280,7 @@ public class SesConfigurationSetService implements SesTaggable {
Objects.requireNonNull(verifiedDomainIdentity, "verifiedDomainIdentity probe is required");
if (domain == null) {
throw SmithyValidationErrors.validationError(
"Value at 'trackingOptions' failed to satisfy constraint: "
+ "Member must not be null");
SmithyValidationErrors.notNullWithoutValue("trackingOptions"));
}
if (domain.isBlank()) {
throw new AwsException("InvalidTrackingOptions",
@@ -30,6 +30,8 @@ import java.util.Set;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
import static io.github.hectorvent.floci.core.common.SmithyValidationErrors.notNullWithoutValue;
/**
* Contact lists and contacts (the {@code contactListStore} + {@code contactStore}), extracted from
* {@link SesService} as the fifth step of the store-based domain split.
@@ -224,7 +226,7 @@ public class SesContactService implements SesTaggable {
private static void validateContactListName(String name) {
if (name == null) {
throw validationError("contactListName", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue("contactListName"));
}
if (name.isBlank()) {
throw new AwsException("BadRequestException", "ContactListName can't be blank.", 400);
@@ -250,20 +252,20 @@ public class SesContactService implements SesTaggable {
// Phase 1 — protocol-layer (Smithy) validation: null members and the subscription-status
// enum. AWS reports these before any service-level constraint.
if (name == null) {
throw validationError("contactListName", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue("contactListName"));
}
if (topics != null) {
for (int i = 0; i < topics.size(); i++) {
Topic t = topics.get(i);
String member = "topics." + (i + 1) + ".member.";
if (t.getTopicName() == null) {
throw validationError(member + "topicName", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue(member + "topicName"));
}
if (t.getDisplayName() == null) {
throw validationError(member + "displayName", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue(member + "displayName"));
}
if (t.getDefaultSubscriptionStatus() == null) {
throw validationError(member + "defaultSubscriptionStatus", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue(member + "defaultSubscriptionStatus"));
}
if (!SUBSCRIPTION_STATUSES.contains(t.getDefaultSubscriptionStatus())) {
throw validationError(member + "defaultSubscriptionStatus",
@@ -545,10 +547,10 @@ public class SesContactService implements SesTaggable {
TopicPreference p = prefs.get(i);
String member = "topicPreferences." + (i + 1) + ".member.";
if (p.getTopicName() == null) {
throw validationError(member + "topicName", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue(member + "topicName"));
}
if (p.getSubscriptionStatus() == null) {
throw validationError(member + "subscriptionStatus", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue(member + "subscriptionStatus"));
}
if (!SUBSCRIPTION_STATUSES.contains(p.getSubscriptionStatus())) {
throw validationError(member + "subscriptionStatus",
@@ -592,7 +594,7 @@ public class SesContactService implements SesTaggable {
// Verified against real AWS: a missing/null required member is a Smithy validation error,
// an empty/blank value is "can't be blank", and only a non-blank malformed value is "invalid".
if (emailAddress == null) {
throw validationError("emailAddress", "Member must not be null");
throw SmithyValidationErrors.badRequest(notNullWithoutValue("emailAddress"));
}
if (emailAddress.isBlank()) {
throw new AwsException("BadRequestException", "EmailAddress can't be blank.", 400);
@@ -100,7 +100,7 @@ final class SesExportMetrics {
private static void validateDimensions(JsonNode dimensions, List<String> violations) {
if (!dimensions.isObject()) {
violations.add(constraint("dimensions", "Member must not be null"));
violations.add(SmithyValidationErrors.notNullWithoutValue(PATH + "dimensions"));
return;
}
if (dimensions.isEmpty()) {
@@ -133,7 +133,7 @@ final class SesExportMetrics {
private static void validateMetrics(JsonNode metrics, List<String> violations) {
if (!metrics.isArray()) {
violations.add(constraint("metrics", "Member must not be null"));
violations.add(SmithyValidationErrors.notNullWithoutValue(PATH + "metrics"));
return;
}
if (metrics.isEmpty()) {
@@ -93,13 +93,12 @@ public class SesIdentityCertificateService {
List<String> violations = new ArrayList<>();
requireIdentityMember(emailIdentity, violations);
if (certificateArn == null) {
violations.add(violation("certificateArn", "Member must not be null"));
violations.add(SmithyValidationErrors.notNullWithoutValue("certificateArn"));
} else {
if (certificateArn.length() < 20) {
violations.add(violation("certificateArn", "Member must have length greater than or equal to 20"));
}
if (certificateArn.length() > 2048) {
violations.add(violation("certificateArn", "Member must have length less than or equal to 2048"));
String certificateArnLength = SmithyValidationErrors.sizeOutOfRange("certificateArn",
certificateArn.length(), 20, 2048);
if (certificateArnLength != null) {
violations.add(certificateArnLength);
}
if (!CERTIFICATE_ARN.matcher(certificateArn).matches()) {
violations.add(violation("certificateArn",
@@ -335,7 +334,7 @@ public class SesIdentityCertificateService {
private static void requireIdentityMember(String emailIdentity, List<String> violations) {
if (emailIdentity == null) {
violations.add(violation("emailIdentity", "Member must not be null"));
violations.add(SmithyValidationErrors.notNullWithoutValue("emailIdentity"));
} else if (emailIdentity.isEmpty()) {
violations.add(violation("emailIdentity", "Member must have length greater than or equal to 1"));
}
@@ -279,8 +279,7 @@ public class SesIdentityController {
if (policyNode.isMissingNode() || policyNode.isNull()) {
// Verified against AWS: a missing/null required member is a Smithy validation error.
throw SmithyValidationErrors.badRequest(
"Value at 'policy' failed to satisfy constraint: "
+ "Member must not be null");
SmithyValidationErrors.notNullWithoutValue("policy"));
}
if (!policyNode.isTextual()) {
// Policy is a String; AWS rejects a non-string with an empty-bodied 400. Don't coerce
@@ -341,7 +341,8 @@ public class SesMetricsController {
private static Instant requireTimestamp(JsonNode query, String field, String member, int position) {
JsonNode node = query.path(field);
if (node.isMissingNode() || node.isNull()) {
throw aggregated(List.of(memberConstraint(position, member, "Member must not be null")));
throw aggregated(List.of(
SmithyValidationErrors.notNullWithoutValue("queries." + position + ".member." + member)));
}
if (node.isNumber()) {
try {
@@ -521,8 +521,7 @@ public class SesReceiptRuleService {
private static void requireMember(List<String> violations, ReceiptAction action,
String member, String path) {
if (action.property(member) == null) {
violations.add("Value at '" + path + "' failed to satisfy constraint: "
+ "Member must not be null");
violations.add(SmithyValidationErrors.notNullWithoutValue(path));
}
}
@@ -733,8 +732,7 @@ public class SesReceiptRuleService {
// Probed: an absent FilterName is the one case the wire rejects; deleting a missing
// or malformed name succeeds without error.
throw SmithyValidationErrors.validationError(
"Value at 'filterName' failed to satisfy "
+ "constraint: Member must not be null");
SmithyValidationErrors.notNullWithoutValue("filterName"));
}
receiptFilterStore.delete(receiptFilterKey(region, filterName));
LOG.infov("Deleted SES receipt filter: {0} in region {1}", filterName, region);
@@ -86,7 +86,7 @@ public class SesReputationEntityService {
requireReference(reference);
if (status == null) {
throw SmithyValidationErrors.badRequest(
"Value at 'sendingStatus' failed to satisfy constraint: Member must not be null");
SmithyValidationErrors.notNullWithoutValue("sendingStatus"));
}
if (!SENDING_STATUSES.contains(status)) {
throw SmithyValidationErrors.badRequest("Value at 'sendingStatus' failed to satisfy constraint: "
@@ -238,7 +238,7 @@ public class SesSendController {
validateTrackingOverrides(request);
JsonNode bulkEntries = request.path("BulkEmailEntries");
if (bulkEntries.isMissingNode() || bulkEntries.isNull()) {
throw constraintViolation(null, "bulkEmailEntries", "Member must not be null");
throw SmithyValidationErrors.badRequest(SmithyValidationErrors.notNullWithoutValue("bulkEmailEntries"));
}
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
if (fromEmailAddress == null || fromEmailAddress.isBlank()) {
@@ -494,11 +494,13 @@ public class SesSendController {
String memberPrefix = location + "." + index + ".member.";
String fileName = attachmentString(node, "FileName", memberPrefix + "fileName", 0, 255);
if (fileName == null) {
throw constraintViolation(null, memberPrefix + "fileName", "Member must not be null");
throw SmithyValidationErrors.badRequest(
SmithyValidationErrors.notNullWithoutValue(memberPrefix + "fileName"));
}
JsonNode rawNode = node.get("RawContent");
if (rawNode == null || rawNode.isNull()) {
throw constraintViolation(null, memberPrefix + "rawContent", "Member must not be null");
throw SmithyValidationErrors.badRequest(
SmithyValidationErrors.notNullWithoutValue(memberPrefix + "rawContent"));
}
byte[] rawContent;
try {
@@ -568,13 +570,13 @@ public class SesSendController {
}
private static AwsException constraintViolation(String value, String path, String constraint) {
String subject = value == null ? "Value" : "Value '" + value + "'";
return SmithyValidationErrors.badRequest(
subject + " at '" + path + "' failed to satisfy constraint: " + constraint);
"Value '" + value + "' at '" + path + "' failed to satisfy constraint: " + constraint);
}
private static AwsException missingHeaderMember(String location, int index, String member) {
return constraintViolation(null, location + "." + index + ".member." + member, "Member must not be null");
return SmithyValidationErrors.badRequest(
SmithyValidationErrors.notNullWithoutValue(location + "." + index + ".member." + member));
}
/**
@@ -407,8 +407,7 @@ public class SesTenantService implements SesTaggable {
public static AssociationResource parseResourceArn(String resourceArn, String accountId, String region) {
if (resourceArn == null) {
throw SmithyValidationErrors.badRequest(
"Value at 'resourceArn' failed to satisfy constraint: "
+ "Member must not be null");
SmithyValidationErrors.notNullWithoutValue("resourceArn"));
}
String[] parts = resourceArn.split(":", 6);
if (parts.length < 6 || !"arn".equals(parts[0])) {
@@ -678,8 +677,7 @@ public class SesTenantService implements SesTaggable {
if (name == null) {
if (createTenantSmithyVariants) {
throw SmithyValidationErrors.badRequest(
"Value at 'tenantName' failed to satisfy "
+ "constraint: Member must not be null");
SmithyValidationErrors.notNullWithoutValue("tenantName"));
}
throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);
}