{"record":{"id":"a951e4a4eeb87ade","repo":"t8y2/dbx","slug":"invalid-collation-option-strength-expected-an-int","errorCode":null,"errorMessage":"Invalid collation option strength: expected an integer from 1 to 5","messagePattern":"Invalid collation option strength: expected an integer from 1 to 5","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":828,"sourceCode":"        Set<String> supported = Set.of(\n            \"locale\", \"strength\", \"caseLevel\", \"caseFirst\", \"numericOrdering\",\n            \"alternate\", \"maxVariable\", \"normalization\", \"backwards\"\n        );\n        for (String key : document.keySet()) {\n            if (!supported.contains(key)) {\n                throw new IllegalArgumentException(\"Unsupported collation option: \" + key);\n            }\n        }\n        String locale = document.getString(\"locale\");\n        if (locale == null || locale.isBlank()) {\n            throw new IllegalArgumentException(\"Invalid collation: locale must not be empty\");\n        }\n\n        Collation.Builder builder = Collation.builder().locale(locale);\n        if (document.containsKey(\"strength\")) {\n            Object strength = document.get(\"strength\");\n            if (!(strength instanceof Number number) || number.doubleValue() != Math.rint(number.doubleValue())) {\n                throw new IllegalArgumentException(\"Invalid collation option strength: expected an integer from 1 to 5\");\n            }\n            int strengthValue = number.intValue();\n            if (strengthValue < 1 || strengthValue > 5) {\n                throw new IllegalArgumentException(\"Invalid collation option strength: expected an integer from 1 to 5\");\n            }\n            builder.collationStrength(CollationStrength.fromInt(strengthValue));\n        }\n        if (document.containsKey(\"caseLevel\")) {\n            builder.caseLevel(collationBoolean(document, \"caseLevel\"));\n        }\n        if (document.containsKey(\"caseFirst\")) {\n            builder.collationCaseFirst(CollationCaseFirst.fromString(collationString(document, \"caseFirst\")));\n        }\n        if (document.containsKey(\"numericOrdering\")) {\n            builder.numericOrdering(collationBoolean(document, \"numericOrdering\"));\n        }\n        if (document.containsKey(\"alternate\")) {\n            builder.collationAlternate(CollationAlternate.fromString(collationString(document, \"alternate\")));","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L810-L846","documentation":"The collation 'strength' option must be an integer from 1 to 5 per the MongoDB/ICU spec. If the value is not a number or has a fractional part, this error is thrown (the range check produces the same message).","triggerScenarios":"Passing strength as a string (\"2\"), a float (1.5), a boolean, or null while the key is present.","commonSituations":"Reading strength from text config or query strings where everything is a string; copying ICU level names like 'primary' instead of the numeric value 1; decimal separators.","solutions":["Pass strength as an integer number: 1, 2, 3, 4, or 5","Convert string values with Integer.parseInt before calling","Map textual levels (primary/secondary/tertiary/quaternary/identical) to 1-5","Omit strength to use the default level 3"],"exampleFix":"// before\n{\"collation\":{\"locale\":\"en\",\"strength\":\"2\"}}\n// after\n{\"collation\":{\"locale\":\"en\",\"strength\":2}}","handlingStrategy":"validation","validationCode":"if (collation.strength != null) {\n  const s = Number(collation.strength);\n  if (!Number.isInteger(s) || s < 1 || s > 5) throw new Error('strength must be an integer 1-5');\n}","typeGuard":"function isValidCollationStrength(v) {\n  return v == null || (typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 5);\n}","tryCatchPattern":"try {\n  result = agent.findOne(params);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().includes('collation option strength')) {\n    params.collation.strength = 3;\n    result = agent.findOne(params);\n  } else throw e;\n}","preventionTips":["Pass strength as a JSON number, never a string","Map textual ICU level names to integers 1-5","Omit strength for the default level 3","Validate strength in config loaders"],"tags":["mongodb","collation","strength","validation"],"backgroundTag":"invalid-option-value","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}