alibaba/Sentinel · error · IllegalArgumentException

baseDir can't be null

Error message

baseDir can't be null

What it means

MetricSearcher scans historical metric log files under baseDir for records matching baseFileName. The directory argument is mandatory; a null baseDir throws IllegalArgumentException because there is no sane default location for metric files and file listing would NPE later.

Source

Thrown at sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java:59

    private Position lastPosition = new Position();

    /**
     * @param baseDir      metric文件所在目录
     * @param baseFileName metric文件名的关键字,比如 alihot-metrics.log
     */
    public MetricSearcher(String baseDir, String baseFileName) {
        this(baseDir, baseFileName, defaultCharset);
    }

    /**
     * @param baseDir      metric文件所在目录
     * @param baseFileName metric文件名的关键字,比如 alihot-metrics.log
     * @param charset
     */
    public MetricSearcher(String baseDir, String baseFileName, Charset charset) {
        if (baseDir == null) {
            throw new IllegalArgumentException("baseDir can't be null");
        }
        if (baseFileName == null) {
            throw new IllegalArgumentException("baseFileName can't be null");
        }
        if (charset == null) {
            throw new IllegalArgumentException("charset can't be null");
        }
        this.baseDir = baseDir;
        if (!baseDir.endsWith(File.separator)) {
            this.baseDir += File.separator;
        }
        this.baseFileName = baseFileName;
        metricsReader = new MetricsReader(charset);
    }

    /**
     * 从beginTime开始,检索recommendLines条(大概)记录。同一秒中的数据是原子的,不能分割成多次查询。
     *

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Pass the actual metric log directory, typically the same dir configured for MetricWriter, e.g. ${user.home}/logs/csp/.
  2. If the dir comes from a property, ensure it is set before constructing the searcher (check RecordLog configuration / SentinelConfig).
  3. Guard with a null check and fall back to the default log dir (MetricWriterLogBaseDir) instead of null.

Example fix

// before
new MetricSearcher(nullMetricDir, "sentinel-dashboard-metrics.log");

// after
String baseDir = metricDir != null ? metricDir : MetricWriter.getBaseDir();
new MetricSearcher(baseDir, "sentinel-dashboard-metrics.log");
Defensive patterns

Strategy: validation

Validate before calling

String baseDir = Objects.requireNonNullElse(config.getMetricDir(),
    MetricWriter.getBaseDir()); // known metric log dir
new MetricSearcher(baseDir, "appName-metrics.log");

Prevention

When it happens

Trigger: new MetricSearcher(null, baseFileName) or new MetricSearcher(null, baseFileName, charset), i.e. any of the three constructors invoked with a null first argument.

Common situations: Building MetricSearcher from configuration where the metric directory property was never set (e.g. sentinel-dashboard reading a missing cigar/metric dir), or refactoring code that previously derived baseDir from a possibly-null variable.

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/ece84891a330e168. Report an issue: GitHub.