alibaba/Sentinel · error · IllegalArgumentException
bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get
Error message
bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get What it means
FileRefreshableDataSource reads a whole config file into a fixed byte buffer (bufSize) on each refresh. Its constructor validates 0 < bufSize <= MAX_SIZE and throws IllegalArgumentException otherwise — same policy as FileInJarReadableDataSource, applied before the file/charset checks.
Source
Thrown at sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileRefreshableDataSource.java:81
public FileRefreshableDataSource(String fileName, Converter<String, T> configParser) throws FileNotFoundException {
this(new File(fileName), configParser, DEFAULT_REFRESH_MS, DEFAULT_BUF_SIZE, DEFAULT_CHAR_SET);
}
public FileRefreshableDataSource(File file, Converter<String, T> configParser, int bufSize)
throws FileNotFoundException {
this(file, configParser, DEFAULT_REFRESH_MS, bufSize, DEFAULT_CHAR_SET);
}
public FileRefreshableDataSource(File file, Converter<String, T> configParser, Charset charset)
throws FileNotFoundException {
this(file, configParser, DEFAULT_REFRESH_MS, DEFAULT_BUF_SIZE, charset);
}
public FileRefreshableDataSource(File file, Converter<String, T> configParser, long recommendRefreshMs, int bufSize,
Charset charset) throws FileNotFoundException {
super(configParser, recommendRefreshMs);
if (bufSize <= 0 || bufSize > MAX_SIZE) {
throw new IllegalArgumentException("bufSize must between (0, " + MAX_SIZE + "], but " + bufSize + " get");
}
if (file == null || file.isDirectory()) {
throw new IllegalArgumentException("File can't be null or a directory");
}
if (charset == null) {
throw new IllegalArgumentException("charset can't be null");
}
this.buf = new byte[bufSize];
this.file = file;
this.charset = charset;
// If the file does not exist, the last modified will be 0.
this.lastModified = file.lastModified();
firstLoad();
}
private void firstLoad() {
try {
T newValue = loadConfig();View on GitHub (pinned to a3f40ba8e9)
Solutions
- Pass a bufSize in (0, MAX_SIZE]; if unsure, omit it and rely on DEFAULT_BUF_SIZE.
- Audit the expression producing bufSize — ensure it cannot be 0 or negative before the constructor call.
- Remember this datasource reads the file in one shot: bufSize must cover the full config file or later reads will fail a size check like the jar variant.
Example fix
// before
new FileRefreshableDataSource<>(file, parser, 3000, Integer.parseInt(props.getProperty("buf", "0")), charset);
// after
int bufSize = Integer.parseInt(props.getProperty("buf", String.valueOf(FileRefreshableDataSource.DEFAULT_BUF_SIZE)));
new FileRefreshableDataSource<>(file, parser, 3000, bufSize, charset); Defensive patterns
Strategy: validation
Validate before calling
int bufSize = props.getProperty("bufSize") == null
? FileRefreshableDataSource.DEFAULT_BUF_SIZE
: Integer.parseInt(props.getProperty("bufSize"));
if (bufSize <= 0 || bufSize > FileRefreshableDataSource.DEFAULT_BUF_SIZE /* MAX_SIZE */) {
throw new ConfigurationException("bufSize out of range: " + bufSize);
}
new FileRefreshableDataSource<>(file, parser, refreshMs, bufSize, charset); Type guard
boolean isValidBufSize(int bufSize) {
return bufSize > 0 && bufSize <= FileRefreshableDataSource.DEFAULT_BUF_SIZE;
} Prevention
- Size bufSize to the maximum expected file size — the whole file is read in one buffer.
- Omit the bufSize argument unless you have measured constraints; defaults are safe.
When it happens
Trigger: new FileRefreshableDataSource(file, parser, recommendRefreshMs, bufSize, charset) with bufSize <= 0 or bufSize > MAX_SIZE; also reachable via the 5-arg overload from the 4-arg convenience constructor only if you pass an explicit bad size (defaults are safe).
Common situations: bufSize derived from a runtime computation (e.g. file length check order) or a config property defaulting to 0; migrating from a version where the argument order/semantics of the varargs constructor changed.
Related errors
- bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get
- recommendRefreshMs must > 0, but {} get
- File can't be null or a directory
- Bad file
- keys empty or null: ${keys}
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/deb30f71b9f30792.
Report an issue: GitHub.