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
FileInJarReadableDataSource reads a config file packaged inside a jar into a fixed byte buffer. bufSize must satisfy 0 < bufSize <= MAX_SIZE (DEFAULT_BUF_SIZE = 1024 * 1024 if you use the convenience constructor); values outside that range throw IllegalArgumentException because the single read cannot handle empty or oversized buffers.
Source
Thrown at sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java:81
}
public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,
int bufSize) throws IOException {
this(jarName, fileInJarName, configParser, bufSize, DEFAULT_CHARSET);
}
public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,
Charset charset) throws IOException {
this(jarName, fileInJarName, configParser, DEFAULT_BUF_SIZE, charset);
}
public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,
int bufSize, Charset charset) throws IOException {
super(configParser);
AssertUtil.assertNotBlank(jarName, "jarName cannot be blank");
AssertUtil.assertNotBlank(fileInJarName, "fileInJarName cannot be blank");
if (bufSize <= 0 || bufSize > MAX_SIZE) {
throw new IllegalArgumentException("bufSize must between (0, " + MAX_SIZE + "], but " + bufSize + " get");
}
AssertUtil.notNull(charset, "charset can't be null");
this.buf = new byte[bufSize];
this.charset = charset;
this.jarName = jarName;
this.fileInJarName = fileInJarName;
initializeJar();
firstLoad();
}
@Override
public String readSource() throws Exception {
if (null == jarEntry) {
// Will throw FileNotFoundException later.
RecordLog.warn(String.format("[FileInJarReadableDataSource] File does not exist: %s", jarFile.getName()));
}
try (InputStream inputStream = jarFile.getInputStream(jarEntry)) {
if (inputStream.available() > buf.length) {View on GitHub (pinned to a3f40ba8e9)
Solutions
- Use a positive bufSize no greater than FileInJarReadableDataSource.MAX_SIZE.
- Simplest: drop the bufSize argument and use the constructor defaulting to DEFAULT_BUF_SIZE (1 MB).
- If the in-jar file truly exceeds MAX_SIZE, that file cannot be loaded by this datasource — split it or raise bufSize only up to MAX_SIZE.
Example fix
// before new FileInJarReadableDataSource<>(jar, name, parser, 0, charset); // after new FileInJarReadableDataSource<>(jar, name, parser, charset); // 1MB default // or an explicit in-range size: new FileInJarReadableDataSource<>(jar, name, parser, 64 * 1024, charset);
Defensive patterns
Strategy: validation
Validate before calling
int bufSize = Math.min(Math.max(requestedBufSize, 1), FileInJarReadableDataSource.DEFAULT_BUF_SIZE); new FileInJarReadableDataSource<>(jarName, fileInJarName, parser, bufSize, charset);
Type guard
boolean isValidBufSize(int bufSize) {
return bufSize > 0 && bufSize <= FileInJarReadableDataSource.DEFAULT_BUF_SIZE /* MAX_SIZE */;
} Prevention
- Unless you need a custom size, use the constructor without bufSize (defaults to 1MB).
- Clamp external bufSize configuration into (0, MAX_SIZE] at the config boundary.
When it happens
Trigger: new FileInJarReadableDataSource(jarName, fileInJarName, parser, bufSize, charset) with bufSize <= 0 or bufSize > MAX_SIZE (the constructor asserts jarName/fileInJarName non-blank first).
Common situations: Sizing the buffer from the actual file length without bounds (a file bigger than MAX_SIZE), passing 0 by default, or computing bufSize from a config property that is unset.
Related errors
- bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get
- recommendRefreshMs must > 0, but {} get
- Size of file <%s> exceeds the bufSize (%d): %d
- keys empty or null: ${keys}
- keys empty or null
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/68a1a809bb024cdf.
Report an issue: GitHub.