{"record":{"id":"7206c43cf2243f1f","repo":"lionsoul2014/ip2region","slug":"ip-verison-not-match-xdb-file-xdbfile-getabsolu","errorCode":null,"errorMessage":"ip verison not match: xdb file ${xdbFile.getAbsolutePath()} (${xVersion.name}), as ${ipVersion.name} expected","messagePattern":"ip verison not match: xdb file (.+?) \\((.+?)\\), as (.+?) expected","errorType":"exception","errorClass":"XdbException","httpStatus":null,"severity":"error","filePath":"binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java","lineNumber":63,"sourceCode":"    // config builder\n    public static ConfigBuilder custom() {\n        return new ConfigBuilder();\n    }\n\n    protected Config(int cachePolicy, Version ipVersion, File xdbFile, \n        Header header, byte[] vIndex, LongByteArray cBuffer, int searchers, boolean fairLock) throws IOException, XdbException {\n        this.cachePolicy = cachePolicy;\n        this.ipVersion = ipVersion;\n\n        this.xdbFile = xdbFile;\n        this.header  = header;\n        this.vIndex  = vIndex;\n        this.cBuffer = cBuffer;\n\n        final Version xVersion = Version.fromHeader(header);\n        // verify the ip version (ipVersion and the version of the xdb file should be the same)\n        if (header.ipVersion != ipVersion.id) {\n            throw new XdbException(\"ip verison not match: xdb file \" \n                + xdbFile.getAbsolutePath() + \" (\" + xVersion.name + \"), as \" + ipVersion.name + \" expected\");\n        }\n\n        this.searchers = searchers;\n        this.fairLock = fairLock;\n    }\n\n    @Override public String toString() {\n        final StringBuffer sb = new StringBuffer();\n        sb.append('{');\n        sb.append(\"cache_policy:\").append(cachePolicy).append(',');\n        sb.append(\"version:\").append(ipVersion.toString()).append(',');\n        sb.append(\"xdb_path:\").append(xdbFile == null ? \"null\" : xdbFile.getAbsolutePath()).append(',');\n        sb.append(\"header:\").append(header.toString()).append(',');\n        if (vIndex == null) {\n            sb.append(\"v_index: null, \");\n        } else {\n            sb.append(\"v_index: {bytes: \").append(vIndex.length).append(\"},\");","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java#L45-L81","documentation":"When building a Config (which wires searchers to a data file), the Java binding compares the IP version requested (IPv4 or IPv6) with the ipVersion recorded in the xdb header. A mismatch — loading an IPv4 database through an IPv6-configured searcher or vice versa — throws XdbException naming the file, its version, and the expected version.","triggerScenarios":"Constructing Config with ipVersion = IPv6 while pointing xdbFile at an IPv4 city xdb (or the reverse); copying config code between the ipv4 and ipv6 sample apps without swapping the db path; using an un-versioned/legacy xdb whose header version does not equal the requested id.","commonSituations":"Deployment where the config's db path was changed (e.g. to an ip2region v4 file) but the code still requests IPv6; teams shipping both city.ipv4.xdb and city.ipv6.xdb and mixing them in shared configuration.","solutions":["Point the config's xdbFile at the database matching the requested IP version (city.ipv4.xdb for IPv4, city.ipv6.xdb for IPv6), or change ipVersion to match the file.","Check Version.fromHeader(header) output to see which family the file actually is before wiring it in.","In shared config, parameterize both the db path and ipVersion together so they can't diverge.","Regenerate the xdb with the maker for the desired IP version if the wrong one was built."],"exampleFix":"// before\nnew Config(xdbFile, header, Version.IPv6, ...) // file is city.ipv4.xdb\n// after\nnew Config(new File(\"data/city.ipv6.xdb\"), header, Version.IPv6, ...)","handlingStrategy":"validation","validationCode":"Version fileVersion = Version.fromHeader(header);\nif (fileVersion.id != ipVersion.id)\n  throw new IllegalArgumentException(\"xdb \" + xdbFile + \" is \" + fileVersion.name + \" but IPv4/IPv6 \" + ipVersion.name + \" expected\");","typeGuard":null,"tryCatchPattern":"try {\n  config = new Config(xdbFile, header, ipVersion, vIndex, cBuffer, searchers, fairLock);\n} catch (XdbException e) {\n  if (e.getMessage().contains(\"ip verison not match\")) {\n    // swap in the db file matching ipVersion, or flip ipVersion to match the file\n    throw new IllegalStateException(\"configure matching db path + ipVersion\", e);\n  }\n  throw e;\n}","preventionTips":["Keep db path and ipVersion in one config object so they can't drift apart.","Name files explicitly (city.ipv4.xdb / city.ipv6.xdb) and assert the suffix matches the configured version at startup.","Smoke-test one lookup per searcher at boot to surface mismatches immediately."],"tags":["java","ipv6","ipv4","configuration","xdb"],"backgroundTag":"ip-version-mismatch","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}