{"record":{"id":"00c8cdf508d658f8","repo":"java-native-access/jna","slug":"win32exception-error-code-from-native-getlasterror-after-00c8cd","errorCode":null,"errorMessage":"Win32Exception (error code from Native.getLastError after FindNextUrlCacheEntry with buffer)","messagePattern":"Win32Exception \\(error code from Native\\.getLastError after FindNextUrlCacheEntry with buffer\\)","errorType":"error_code","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java","lineNumber":109,"sourceCode":"\n                if (!result) {\n                    lastError = Native.getLastError();\n                    if (lastError == WinError.ERROR_NO_MORE_ITEMS) {\n                        break;\n                    } else if (lastError != WinError.ERROR_SUCCESS && lastError != WinError.ERROR_INSUFFICIENT_BUFFER) {\n                        throw new Win32Exception(lastError);\n                    }\n                }\n\n                entry = new INTERNET_CACHE_ENTRY_INFO(size.getValue());\n                result = Wininet.INSTANCE.FindNextUrlCacheEntry(cacheHandle, entry, size);\n\n                if (!result) {\n                    lastError = Native.getLastError();\n                    if (lastError == WinError.ERROR_NO_MORE_ITEMS) {\n                        break;\n                    } else if (lastError != WinError.ERROR_SUCCESS && lastError != WinError.ERROR_INSUFFICIENT_BUFFER) {\n                        throw new Win32Exception(lastError);\n                    }\n                }\n                items.add(entry);\n            }\n\n            for (INTERNET_CACHE_ENTRY_INFO item : items) {\n                cacheItems.put(item.lpszSourceUrlName.getWideString(0), item.lpszLocalFileName == null ? \"\" : item.lpszLocalFileName.getWideString(0));\n            }\n\n        } catch (Win32Exception e) {\n            we = e;\n        } finally {\n            if (cacheHandle != null) {\n                if (!Wininet.INSTANCE.FindCloseUrlCache(cacheHandle)) {\n                    if (we != null) {\n                        Win32Exception e = new Win32Exception(Native.getLastError());\n                        e.addSuppressedReflected(we);\n                        we = e;","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java#L91-L127","documentation":"Functionally the same failure as error 285 but thrown on the next loop iteration: after FindNextUrlCacheEntry reports ERROR_INSUFFICIENT_BUFFER (or ERROR_SUCCESS with a false return), the code allocates a new INTERNET_CACHE_ENTRY_INFO and the subsequent FindNextUrlCacheEntry call with the new buffer fails, producing a Win32Exception with the fresh GetLastError() code. It means a mid-enumeration retry with a resized buffer still failed.","triggerScenarios":"getCache() loop iteration where FindNextUrlCacheEntry returned false with ERROR_INSUFFICIENT_BUFFER, a bigger entry buffer was allocated, and the retry call still failed (entry removed concurrently, invalid handle, or hard WinINet error).","commonSituations":"Enumerating a very active cache where entries are being added/removed during iteration; thread-affinity violations of WinINet handles; allocation/structure-size mismatches on unusual Windows versions.","solutions":["Retry the whole enumeration once on Win32Exception, since the cache is mutable and a fresh run usually succeeds","Catch and treat as end-of-enumeration, returning items collected so far","Run enumeration on the creating thread and avoid concurrent cache access","Report/persist the error code for diagnosis rather than silently swallowing all Win32Exceptions"],"exampleFix":"// before\nList<INTERNET_CACHE_ENTRY_INFO> items = WininetUtil.getCache();\n// after\nList<INTERNET_CACHE_ENTRY_INFO> items;\ntry {\n    items = WininetUtil.getCache();\n} catch (Win32Exception e) {\n    items = Collections.emptyList(); // or retry once\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"List<INTERNET_CACHE_ENTRY_INFO> items;\ntry {\n    items = WininetUtil.getCache();\n} catch (Win32Exception e) {\n    items = Collections.emptyList(); // accept partial enumeration\n}","preventionTips":["Accept partial results from a mutable cache","Re-run enumeration if completeness matters","Never share WinINet handles across threads"],"tags":["wininet","windows","url-cache","win32-exception"],"backgroundTag":"api-error-response","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"}