{"record":{"id":"d9fa7b7817be9b73","repo":"java-native-access/jna","slug":"size-must-greater-than-size-requested-size","errorCode":null,"errorMessage":"Size must greater than {size()}, requested {size}","messagePattern":"Size must greater than (.+?), requested (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/WinNT.java","lineNumber":906,"sourceCode":"     * This structure is non-trivial since it is a pattern stamped into a large\n     * block of result memory rather than something that stands alone or is used\n     * for input.\n     */\n    @FieldOrder({\"NextEntryOffset\", \"Action\", \"FileNameLength\", \"FileName\"})\n    public static class FILE_NOTIFY_INFORMATION extends Structure {\n        public int NextEntryOffset;\n        public int Action;\n        public int FileNameLength;\n        // filename is not nul-terminated, so we can't use a String/WString\n        public char[] FileName = new char[1];\n\n        private FILE_NOTIFY_INFORMATION() {\n            super();\n        }\n\n        public FILE_NOTIFY_INFORMATION(int size) {\n            if (size < size()) {\n                throw new IllegalArgumentException(\"Size must greater than \"\n                        + size() + \", requested \" + size);\n            }\n            allocateMemory(size);\n        }\n\n        /**\n         * WARNING: this filename may be either the short or long form of the\n         * filename.\n         * @return filename\n         */\n        public String getFilename() {\n            return new String(FileName, 0, FileNameLength / 2);\n        }\n\n        @Override\n        public void read() {\n            // avoid reading filename until we know how long it is\n            FileName = new char[0];","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java#L888-L924","documentation":"FILE_NOTIFY_INFORMATION(int size) allocates native memory for a ReadDirectoryChangesW buffer and validates that the requested byte size is at least the minimum structure size(). Requesting anything smaller cannot hold even one notification record, so the constructor throws this IllegalArgumentException before allocating.","triggerScenarios":"Calling new FILE_NOTIFY_INFORMATION(n) where n < size() — e.g. passing 0, a guess like 4 bytes, or computing buffer size from an entry count without multiplying by the record size.","commonSituations":"Config-driven buffer sizes with a too-small default; users assuming size is per-entry rather than total bytes; refactoring that replaced a computed size with a hard-coded minimum.","solutions":["Pass a size >= FILE_NOTIFY_INFORMATION.size(), typically a multiple of it.","Use a realistic buffer such as 64 KB (commonly used with ReadDirectoryChangesW).","Compute size as records * size() if a record count is what you actually have.","Add a guard: size = Math.max(size, FILE_NOTIFY_INFORMATION.size()) before constructing."],"exampleFix":"// before\nnew FILE_NOTIFY_INFORMATION(8);\n// after\nint size = Math.max(64 * 1024, FILE_NOTIFY_INFORMATION.size());\nnew FILE_NOTIFY_INFORMATION(size);","handlingStrategy":"validation","validationCode":"int requested = 64 * 1024;\nif (requested < com.sun.jna.platform.win32.WinNT.FILE_NOTIFY_INFORMATION.size())\n    throw new IllegalArgumentException(\"buffer too small: \" + requested);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always allocate at least size() bytes; prefer a 64 KB buffer.","Compute size from record counts multiplied by size().","Validate config-supplied buffer sizes against the minimum."],"tags":["windows","filesystem","argument"],"backgroundTag":"argument-out-of-range","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}