{"record":{"id":"f985c19553c7d9b1","repo":"alibaba/Sentinel","slug":"basefilename-can-t-be-null","errorCode":null,"errorMessage":"baseFileName can't be null","messagePattern":"baseFileName can't be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java","lineNumber":62,"sourceCode":"    /**\n     * @param baseDir      metric文件所在目录\n     * @param baseFileName metric文件名的关键字，比如 alihot-metrics.log\n     */\n    public MetricSearcher(String baseDir, String baseFileName) {\n        this(baseDir, baseFileName, defaultCharset);\n    }\n\n    /**\n     * @param baseDir      metric文件所在目录\n     * @param baseFileName metric文件名的关键字，比如 alihot-metrics.log\n     * @param charset\n     */\n    public MetricSearcher(String baseDir, String baseFileName, Charset charset) {\n        if (baseDir == null) {\n            throw new IllegalArgumentException(\"baseDir can't be null\");\n        }\n        if (baseFileName == null) {\n            throw new IllegalArgumentException(\"baseFileName can't be null\");\n        }\n        if (charset == null) {\n            throw new IllegalArgumentException(\"charset can't be null\");\n        }\n        this.baseDir = baseDir;\n        if (!baseDir.endsWith(File.separator)) {\n            this.baseDir += File.separator;\n        }\n        this.baseFileName = baseFileName;\n        metricsReader = new MetricsReader(charset);\n    }\n\n    /**\n     * 从beginTime开始，检索recommendLines条(大概)记录。同一秒中的数据是原子的，不能分割成多次查询。\n     *\n     * @param beginTimeMs    检索的最小时间戳\n     * @param recommendLines 查询最多想得到的记录条数，返回条数会尽可能不超过这个数字。但是为保证每一秒的数据不被分割，有时候\n     *                       返回的记录条数会大于该数字。","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java#L44-L80","documentation":"MetricSearcher needs the metric file name keyword (e.g. alihot-metrics.log or sentinel-dashboard-metrics.log) to locate metric files in baseDir. A null baseFileName throws IllegalArgumentException because the searcher would have nothing to pattern-match file names against.","triggerScenarios":"new MetricSearcher(baseDir, null) or new MetricSearcher(baseDir, null, charset) — the second constructor argument is null.","commonSituations":"Passing a resource name loaded from a null system property or constant; building the searcher generically without deciding which app's metric files to query.","solutions":["Pass the metric file name keyword used by MetricWriter for the target app (usually appName + '-metrics.log').","Verify the variable supplying baseFileName is initialized (not a failed property lookup returning null).","If searching the dashboard's own metrics, use the same naming convention as the logs written under baseDir."],"exampleFix":"// before\nnew MetricSearcher(baseDir, null);\n\n// after\nnew MetricSearcher(baseDir, appName + \"-metrics.log\");","handlingStrategy":"validation","validationCode":"String fileName = appName + \"-metrics.log\"; // deterministic, never null\nnew MetricSearcher(baseDir, fileName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build baseFileName from the same convention MetricWriter uses to write the files.","Assert non-null inputs in a small factory: MetricSearcher.create(dir, name)."],"tags":["sentinel","metrics","search","constructor-validation"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}