{"record":{"id":"68a1a809bb024cdf","repo":"alibaba/Sentinel","slug":"bufsize-must-between-0-max-size-but-bufsi","errorCode":null,"errorMessage":"bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get","messagePattern":"bufSize must between \\(0, (.+?)\\], but (.+?) get","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java","lineNumber":81,"sourceCode":"    }\n\n    public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,\n                                       int bufSize) throws IOException {\n        this(jarName, fileInJarName, configParser, bufSize, DEFAULT_CHARSET);\n    }\n\n    public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,\n                                       Charset charset) throws IOException {\n        this(jarName, fileInJarName, configParser, DEFAULT_BUF_SIZE, charset);\n    }\n\n    public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,\n                                       int bufSize, Charset charset) throws IOException {\n        super(configParser);\n        AssertUtil.assertNotBlank(jarName, \"jarName cannot be blank\");\n        AssertUtil.assertNotBlank(fileInJarName, \"fileInJarName cannot be blank\");\n        if (bufSize <= 0 || bufSize > MAX_SIZE) {\n            throw new IllegalArgumentException(\"bufSize must between (0, \" + MAX_SIZE + \"], but \" + bufSize + \" get\");\n        }\n        AssertUtil.notNull(charset, \"charset can't be null\");\n        this.buf = new byte[bufSize];\n        this.charset = charset;\n        this.jarName = jarName;\n        this.fileInJarName = fileInJarName;\n        initializeJar();\n        firstLoad();\n    }\n\n    @Override\n    public String readSource() throws Exception {\n        if (null == jarEntry) {\n            // Will throw FileNotFoundException later.\n            RecordLog.warn(String.format(\"[FileInJarReadableDataSource] File does not exist: %s\", jarFile.getName()));\n        }\n        try (InputStream inputStream = jarFile.getInputStream(jarEntry)) {\n            if (inputStream.available() > buf.length) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java#L63-L99","documentation":"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.","triggerScenarios":"new FileInJarReadableDataSource(jarName, fileInJarName, parser, bufSize, charset) with bufSize <= 0 or bufSize > MAX_SIZE (the constructor asserts jarName/fileInJarName non-blank first).","commonSituations":"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.","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."],"exampleFix":"// before\nnew FileInJarReadableDataSource<>(jar, name, parser, 0, charset);\n\n// after\nnew FileInJarReadableDataSource<>(jar, name, parser, charset); // 1MB default\n// or an explicit in-range size:\nnew FileInJarReadableDataSource<>(jar, name, parser, 64 * 1024, charset);","handlingStrategy":"validation","validationCode":"int bufSize = Math.min(Math.max(requestedBufSize, 1), FileInJarReadableDataSource.DEFAULT_BUF_SIZE);\nnew FileInJarReadableDataSource<>(jarName, fileInJarName, parser, bufSize, charset);","typeGuard":"boolean isValidBufSize(int bufSize) {\n    return bufSize > 0 && bufSize <= FileInJarReadableDataSource.DEFAULT_BUF_SIZE /* MAX_SIZE */;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["sentinel","datasource","jar","buffer","validation"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}