{"record":{"id":"5b428656074deae4","repo":"floci-io/floci","slug":"inconsistentquantities","errorCode":"InconsistentQuantities","errorMessage":"The value of Quantity does not match the number of items.","messagePattern":"The value of Quantity does not match the number of items\\.","errorType":"error_code","errorClass":"AwsException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java","lineNumber":2785,"sourceCode":"            return quantity;\n        } catch (NumberFormatException e) {\n            throw new AwsException(\n                    \"InvalidArgument\",\n                    \"TrustedKeyGroups Quantity must be a non-negative integer.\",\n                    400);\n        }\n    }\n\n    private static void validateTrustedKeyGroupsQuantity(\n            Integer quantity, int itemCount) {\n        if (quantity == null) {\n            throw new AwsException(\n                    \"InvalidArgument\",\n                    \"TrustedKeyGroups must include Quantity.\",\n                    400);\n        }\n        if (quantity != itemCount) {\n            throw new AwsException(\n                    \"InconsistentQuantities\",\n                    \"The value of Quantity does not match the number of items.\",\n                    400);\n        }\n    }\n\n    private static void validateEnabledTrustedKeyGroups(\n            boolean enabled, int itemCount) {\n        if (enabled && itemCount == 0) {\n            throw new AwsException(\n                    \"InvalidArgument\",\n                    \"TrustedKeyGroups cannot be enabled without a key group.\",\n                    400);\n        }\n    }\n\n    private List<String> parseAliases(String body) {\n        List<String> result = new ArrayList<>();","sourceCodeStart":2767,"sourceCodeEnd":2803,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java#L2767-L2803","documentation":"Floci's CloudFront emulator cross-checks the declared Quantity against the actual number of KeyGroupId items in a TrustedKeyGroups block. If they differ it throws InconsistentQuantities (HTTP 400), the AWS error used for count/item mismatches in list-encoded XML.","triggerScenarios":"Sending <Quantity>3</Quantity> with only 2 KeyGroupId items (or vice versa) in DefaultCacheBehavior or any CacheBehavior's TrustedKeyGroups.","commonSituations":"Hardcoded Quantity that goes stale when items are added/removed; hand-merged configs where the list changed but the count was not updated.","solutions":["Set Quantity to exactly the number of KeyGroupId elements in Items","Derive Quantity programmatically from the list size instead of hardcoding","After editing a config fetched from GET, recount items before resubmitting"],"exampleFix":"<!-- before: says 3, lists 2 -->\n<Quantity>3</Quantity>\n<Items><KeyGroupId>kg-1</KeyGroupId><KeyGroupId>kg-2</KeyGroupId></Items>\n\n<!-- after -->\n<Quantity>2</Quantity>\n<Items><KeyGroupId>kg-1</KeyGroupId><KeyGroupId>kg-2</KeyGroupId></Items>","handlingStrategy":"validation","validationCode":"static void checkQuantityMatches(Integer declared, List<String> items) {\n    if (declared == null || declared != items.size()) {\n        throw new IllegalArgumentException(\n            \"Quantity \" + declared + \" != item count \" + items.size());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    cf.updateDistribution(req -> req.id(id).ifMatch(etag).distributionConfig(cfg));\n} catch (CloudFrontException e) {\n    if (\"InconsistentQuantities\".equals(e.awsErrorDetails().errorCode())) {\n        // set Quantity = items.size() and retry once\n    } else { throw e; }\n}","preventionTips":["Derive Quantity from the same list object you serialize, at serialization time","Never hand-edit one of Quantity/Items without updating the other"],"tags":["cloudfront","trusted-key-groups","quantity","consistency","xml"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}