{"record":{"id":"765c9c43c4388205","repo":"alibaba/spring-cloud-alibaba","slug":"sentinel-starter-datasource-file-cannot-be-nu","errorCode":null,"errorMessage":"[Sentinel Starter] DataSource {} file cannot be null","messagePattern":"\\[Sentinel Starter\\] DataSource (.+?) file cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java","lineNumber":86,"sourceCode":"\n\tpublic void setRecommendRefreshMs(long recommendRefreshMs) {\n\t\tthis.recommendRefreshMs = recommendRefreshMs;\n\t}\n\n\tpublic int getBufSize() {\n\t\treturn bufSize;\n\t}\n\n\tpublic void setBufSize(int bufSize) {\n\t\tthis.bufSize = bufSize;\n\t}\n\n\t@Override\n\tpublic void preCheck(String dataSourceName) {\n\t\tsuper.preCheck(dataSourceName);\n\t\tString file = this.getFile();\n\t\tif (file == null) {\n\t\t\tthrow new IllegalArgumentException(\"[Sentinel Starter] DataSource \" + dataSourceName\n\t\t\t\t\t+ \" file cannot be null\");\n\t\t}\n\t\ttry {\n\t\t\tthis.setFile(\n\t\t\t\t\tResourceUtils.getFile(StringUtils.trimAllWhitespace(file))\n\t\t\t\t\t\t\t.getAbsolutePath());\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"[Sentinel Starter] DataSource \" + dataSourceName\n\t\t\t\t\t+ \" handle file [\" + file + \"] error: \" + e.getMessage(),\n\t\t\t\t\te);\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":68,"sourceCodeEnd":103,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/FileDataSourceProperties.java#L68-L103","documentation":"Thrown by FileDataSourceProperties.preCheck during Sentinel datasource initialization when the file field is null. The file field is @Nullable with a @NotEmpty validation annotation but no default value. preCheck calls super.preCheck first, then checks if file is null. The dataSourceName in the message identifies which datasource entry in spring.cloud.sentinel.datasource triggered the error.","triggerScenarios":"Configuring a Sentinel datasource of type 'file' (spring.cloud.sentinel.datasource.<name>.file) without specifying the file property. Since the field has no default, any file-type datasource that omits the file path hits this check.","commonSituations":"1) Developer declares spring.cloud.sentinel.datasource.ds1.file but forgets the nested 'file' property. 2) Configuration uses a placeholder like ${FILE_PATH} that resolves to empty or is not set in the environment. 3) Copy-paste from a template that had the file path as a TODO.","solutions":["Add spring.cloud.sentinel.datasource.<name>.file.file=<path-to-rules-file> to your configuration.","Ensure the file property is set to a valid file path or Spring resource location (e.g., classpath:sentinel-rules.json or file:/etc/app/rules.json).","If using a placeholder, ensure the environment variable is set and non-empty."],"exampleFix":"# before (broken — file path missing)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          file:\n            charset: utf-8\n\n# after (fixed)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          file:\n            file: classpath:sentinel-rules.json\n            charset: utf-8","handlingStrategy":"validation","validationCode":"// Ensure the file property is set for file-type Sentinel datasources\nString filePath = props.getFile().getFile();\nif (!StringUtils.hasText(filePath)) {\n    throw new IllegalArgumentException(\n        \"Sentinel file datasource requires a non-empty 'file' property\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the 'file' property when declaring a file-type Sentinel datasource.","Use configuration validation groups or @NotEmpty annotations at the binding level.","Validate the file path exists and is readable before application startup in a health check."],"tags":["sentinel","file-datasource","datasource","configuration","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}