{"record":{"id":"07aa1f7144a2331b","repo":"elastic/elasticsearch","slug":"sniffintervalmillis-must-be-greater-than-0","errorCode":null,"errorMessage":"sniffIntervalMillis must be greater than 0","messagePattern":"sniffIntervalMillis must be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"client/sniffer/src/main/java/org/elasticsearch/client/sniff/SnifferBuilder.java","lineNumber":54,"sourceCode":"    private long sniffAfterFailureDelayMillis = DEFAULT_SNIFF_AFTER_FAILURE_DELAY;\n    private NodesSniffer nodesSniffer;\n\n    /**\n     * Creates a new builder instance by providing the {@link RestClient} that will be used to communicate with elasticsearch\n     */\n    SnifferBuilder(RestClient restClient) {\n        Objects.requireNonNull(restClient, \"restClient cannot be null\");\n        this.restClient = restClient;\n    }\n\n    /**\n     * Sets the interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when\n     * sniffOnFailure is disabled or when there are no failures between consecutive sniff executions.\n     * @throws IllegalArgumentException if sniffIntervalMillis is not greater than 0\n     */\n    public SnifferBuilder setSniffIntervalMillis(int sniffIntervalMillis) {\n        if (sniffIntervalMillis <= 0) {\n            throw new IllegalArgumentException(\"sniffIntervalMillis must be greater than 0\");\n        }\n        this.sniffIntervalMillis = sniffIntervalMillis;\n        return this;\n    }\n\n    /**\n     * Sets the delay of a sniff execution scheduled after a failure (in milliseconds)\n     */\n    public SnifferBuilder setSniffAfterFailureDelayMillis(int sniffAfterFailureDelayMillis) {\n        if (sniffAfterFailureDelayMillis <= 0) {\n            throw new IllegalArgumentException(\"sniffAfterFailureDelayMillis must be greater than 0\");\n        }\n        this.sniffAfterFailureDelayMillis = sniffAfterFailureDelayMillis;\n        return this;\n    }\n\n    /**\n     * Sets the {@link NodesSniffer} to be used to read hosts. A default instance of {@link ElasticsearchNodesSniffer}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/client/sniffer/src/main/java/org/elasticsearch/client/sniff/SnifferBuilder.java#L36-L72","documentation":"SnifferBuilder guard: the periodic sniff interval (milliseconds between scheduled ordinary sniffs) must be strictly positive. Zero or negative would mean never sniffing or scheduling infinitely tight loops, so the builder rejects it.","triggerScenarios":"Calling Sniffer.builder(client).setSniffIntervalMillis(0) or with a value computed from config that resolved to <= 0.","commonSituations":"Default-overriding config that left the interval unset then passed 0; arithmetic that produced 0 or negative; misreading the unit (passing seconds instead of ms).","solutions":["Pass a positive value in milliseconds, e.g. 300000 (5 minutes) which is near the default.","Validate config-derived intervals before calling the setter.","Double-check the unit: this API is milliseconds, not seconds."],"exampleFix":"// before\nSniffer.builder(client).setSniffIntervalMillis(intervalSeconds).build(); // wrong unit / 0\n// after\nSniffer.builder(client).setSniffIntervalMillis(Math.max(1, intervalSeconds * 1000)).build();","handlingStrategy":"validation","validationCode":"if (intervalMs <= 0) throw new IllegalArgumentException(\"sniffIntervalMillis must be > 0; got \" + intervalMs);\nSniffer.builder(client).setSniffIntervalMillis(intervalMs);","typeGuard":"sniffIntervalMillis > 0","tryCatchPattern":null,"preventionTips":["Validate config values before forwarding them to the builder.","Remember the unit is milliseconds."],"tags":["sniffer","configuration","validation","timeout"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}