{"record":{"id":"168ffc2af9093fed","repo":"apache/cassandra","slug":"mintokenlength-must-be-greater-than-zero","errorCode":null,"errorMessage":"minTokenLength must be greater than zero","messagePattern":"minTokenLength must be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/index/sasi/analyzer/StandardTokenizerOptions.java","lineNumber":185,"sourceCode":"        {\n            this.allTermsToUpperCase = allTermsToUpperCase;\n            return this;\n        }\n\n        public OptionsBuilder alwaysLowerCaseTerms(boolean allTermsToLowerCase)\n        {\n            this.allTermsToLowerCase = allTermsToLowerCase;\n            return this;\n        }\n\n        /**\n         * Set the min allowed token length.  Any token shorter\n         * than this is skipped.\n         */\n        public OptionsBuilder minTokenLength(int minTokenLength)\n        {\n            if (minTokenLength < 1)\n                throw new IllegalArgumentException(\"minTokenLength must be greater than zero\");\n            this.minTokenLength = minTokenLength;\n            return this;\n        }\n\n        /**\n         * Set the max allowed token length.  Any token longer\n         * than this is skipped.\n         */\n        public OptionsBuilder maxTokenLength(int maxTokenLength)\n        {\n            if (maxTokenLength < 1)\n                throw new IllegalArgumentException(\"maxTokenLength must be greater than zero\");\n            this.maxTokenLength = maxTokenLength;\n            return this;\n        }\n\n        public StandardTokenizerOptions build()\n        {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sasi/analyzer/StandardTokenizerOptions.java#L167-L203","documentation":"StandardTokenizerOptions.OptionsBuilder.minTokenLength validates that the minimum token length is at least 1; a token shorter than minTokenLength is skipped by the tokenizer. Passing 0 or a negative value throws IllegalArgumentException since it would be meaningless.","triggerScenarios":"Building StandardAnalyzer options with .minTokenLength(0) or a negative int, e.g. from a parsed 'token_length_min' option value of '0'.","commonSituations":"Users specifying min token length 0 in index options expecting 'no limit'; parsing config values without lower-bound checks.","solutions":["Pass minTokenLength >= 1 (1 disables length filtering effectively)","Omit minTokenLength to use the default","Clamp parsed option values: Math.max(1, value)"],"exampleFix":"// before\nnew StandardTokenizerOptions.Builder().minTokenLength(0).build();\n// after\nnew StandardTokenizerOptions.Builder().minTokenLength(1).build();","handlingStrategy":"validation","validationCode":"int min = Integer.parseInt(options.getOrDefault(\"token_length_min\", \"1\"));\nif (min < 1) throw new IllegalArgumentException(\"minTokenLength must be >= 1\");","typeGuard":null,"tryCatchPattern":"try { builder.minTokenLength(min).build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"minTokenLength\")) { builder.minTokenLength(1).build(); } else throw e; }","preventionTips":["Clamp parsed length options with Math.max(1, value)","Use defaults instead of 0 to mean 'no limit'"],"tags":["sasi","tokenizer","options-builder","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}