{"record":{"id":"55f0f1198b2e6d85","repo":"YunaiV/yudao-cloud","slug":"areautils","errorCode":null,"errorMessage":"AreaUtils 初始化失败","messagePattern":"AreaUtils 初始化失败","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java","lineNumber":67,"sourceCode":"            // 从 csv 中加载数据\n            List<CsvRow> rows = CsvUtil.getReader().read(ResourceUtil.getUtf8Reader(\"area.csv\")).getRows();\n            rows.remove(0); // 删除 header\n            for (CsvRow row : rows) {\n                Area area = new Area(Integer.valueOf(row.get(0)), row.get(1), Integer.valueOf(row.get(2)), null, new ArrayList<>());\n                areas.put(area.getId(), area);\n            }\n\n            // 构建父子关系：因为 Area 中没有 parentId 字段,所以需要重复读取\n            for (CsvRow row : rows) {\n                Area area = areas.get(Integer.valueOf(row.get(0))); // 自己\n                Area parent = areas.get(Integer.valueOf(row.get(3))); // 父\n                Assert.isTrue(area != parent, \"{}:父子节点相同\", area.getName());\n                area.setParent(parent);\n                parent.getChildren().add(area);\n            }\n            log.info(\"启动加载 AreaUtils 成功，耗时 ({}) 毫秒\", System.currentTimeMillis() - now);\n        } catch (Exception e) {\n            throw new RuntimeException(\"AreaUtils 初始化失败\", e);\n        }\n    }\n\n    /**\n     * 获得指定编号对应的区域\n     *\n     * @param id 区域编号\n     * @return 区域\n     */\n    public static Area getArea(Integer id) {\n        return areas.get(id);\n    }\n\n    /**\n     * 获得指定区域对应的编号\n     *\n     * @param pathStr 区域路径，例如说：河南省/石家庄市/新华区\n     * @return 区域","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/YunaiV/yudao-cloud/blob/477be9dd49ab7223a972a6abdff0684d6423dec3/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java#L49-L85","documentation":"AreaUtils statically loads china-area CSV data (areas + parent/child links) from the classpath in a static initializer. Any failure — missing resource, malformed CSV row, Integer.parseInt on a bad code, or the Assert '父子节点相同' (area is its own parent) — is wrapped in RuntimeException('AreaUtils 初始化失败'). The exception type loses the detail; the cause carries it.","triggerScenarios":"First touch of AreaUtils (class loading) in an app where area.csv / csv resource was not packaged (filtered out of the fat jar), or the CSV was hand-edited so column 0 (id) equals column 3 (parentId) for some row, or a row has non-numeric id.","commonSituations":"Maven shade/assembly excluding resources; a custom-region CSV edit introducing a self-loop or duplicate id; trimming the jar for serverless and accidentally removing the data file; encoding issues (GBK vs UTF-8) breaking column parsing.","solutions":["Read getCause() to see the real failure: FileNotFoundException/IOException (missing resource), NumberFormatException (bad id), IllegalArgumentException (parent==self).","Ensure the area CSV resource ships in the jar (check jar tf or target/classes for the resource path).","If the CSV was customized, validate every row: id != parentId and both columns numeric.","Restore the stock resource file if edits corrupted it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// startup smoke check\nif (AreaUtils.class.getResource(\"/area.csv\") == null) { // adjust to actual resource path\n    throw new IllegalStateException(\"area CSV resource missing from classpath\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Area area = AreaUtils.getArea(id);\n} catch (ExceptionInInitializerError e) {\n    Throwable cause = e.getCause(); // RuntimeException with real reason\n    log.error(\"AreaUtils init failed: {}\", cause.getCause());\n}","preventionTips":["Verify resource inclusion in the packaged artifact during CI (jar tf | grep)","Never hand-edit region CSVs without validating id != parentId and numeric codes"],"tags":["yudao","initialization","classpath","resource","csv","area"],"backgroundTag":null,"analyzedSha":"477be9dd49ab7223a972a6abdff0684d6423dec3","analyzedAt":"2026-08-14T13:35:31.121Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}