{"record":{"id":"a194dfa9098d2eaf","repo":"lionsoul2014/ip2region","slug":"invalid-cache-policy-name","errorCode":null,"errorMessage":"invalid cache policy `${name}`","messagePattern":"invalid cache policy `(.+?)`","errorType":"validation","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java","lineNumber":102,"sourceCode":"            sb.append(\"c_buffer: null, \");\n        } else {\n            sb.append(\"c_buffer: {bytes: \").append(cBuffer.length()).append(\"},\");\n        }\n        sb.append(\"searchers:\").append(searchers);\n        sb.append('}');\n        return sb.toString();\n    }\n\n    public static final int cachePolicyFromName(String name) throws InvalidConfigException {\n        final String lName = name.toLowerCase();\n        if (lName.equals(\"file\") || lName.equals(\"nocache\")) {\n            return NoCache;\n        } else if (lName.equals(\"vectorindex\") || lName.equals(\"vindex\") || lName.equals(\"vindexcache\")) {\n            return VIndexCache;\n        } else if (lName.equals(\"content\") || lName.equals(\"buffercache\")) {\n            return BufferCache;\n        } else {\n            throw new InvalidConfigException(\"invalid cache policy `\" + name + \"`\");\n        }\n    }\n}","sourceCodeStart":84,"sourceCodeEnd":105,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java#L84-L105","documentation":"cachePolicyFromName maps a user-supplied policy string (case-insensitive) to a cache-policy constant: none/file, vectorindex/vindex/vindexcache, or content/buffercache. Any other value throws InvalidConfigException listing the offending name.","triggerScenarios":"Passing a policy string like \"memory\", \"full\", \"VECTOR\" (with extra chars), \"vecindex\" (typo), or a null/empty name to cachePolicyFromName or wherever a policy string is configured (Searcher config, CLI flags, Spring properties).","commonSituations":"Typos in application.yml/env vars; porting from docs of another ip2region binding that uses different policy names; users inventing intuitive names like 'cache' or 'ram'.","solutions":["Use one of the accepted names: \"file\"/\"none\", \"vectorindex\"/\"vindex\"/\"vindexcache\", or \"content\"/\"buffercache\" (case-insensitive).","Fix the typo in the configuration property/argument supplying the policy name.","Validate user/CLI input against the allowed set before passing it in, and fall back to a default (e.g. VIndexCache) when absent."],"exampleFix":"// before\nSearcher.cachePolicyFromName(\"full-cache\"); // throws\n// after\nString policy = (name == null) ? \"vectorindex\" : name.toLowerCase();\nSearcher.cachePolicyFromName(policy);","handlingStrategy":"validation","validationCode":"private static final Set<String> VALID = Set.of(\"file\",\"none\",\"vectorindex\",\"vindex\",\"vindexcache\",\"content\",\"buffercache\");\nif (policy != null && !VALID.contains(policy.toLowerCase()))\n  throw new IllegalArgumentException(\"invalid cache policy \" + policy);","typeGuard":null,"tryCatchPattern":"try {\n  policy = cachePolicyFromName(name);\n} catch (InvalidConfigException e) {\n  log.warn(\"unknown cache policy {}, falling back to vectorindex\", name);\n  policy = cachePolicyFromName(\"vectorindex\");\n}","preventionTips":["Centralize the policy string in a constant/enum instead of scattering literals in config.","List accepted values in your configuration docs/schema (e.g. application.yml comments).","Validate config at startup (fail fast) rather than when the first searcher is built."],"tags":["java","configuration","cache-policy","invalid-argument"],"backgroundTag":"invalid-config-value","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}