{"record":{"id":"855efd887c40fde2","repo":"java-native-access/jna","slug":"failed-to-enumerate-results","errorCode":null,"errorMessage":"Failed to enumerate results.","messagePattern":"Failed to enumerate results\\.","errorType":"exception","errorClass":"com.sun.jna.platform.win32.COM.COMException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java","lineNumber":311,"sourceCode":"            HRESULT hres = null;\n            for (T property : propertyEnum.getEnumConstants()) {\n                wstrMap.put(property, new WString(property.name()));\n            }\n            while (enumerator.getPointer() != Pointer.NULL) {\n                // Enumerator will be released by calling method so no need to\n                // release it here.\n                hres = enumerator.Next(timeout, pclsObj.length, pclsObj, uReturn);\n                // Enumeration complete or no more data; we're done, exit the loop\n                if (hres.intValue() == Wbemcli.WBEM_S_FALSE || hres.intValue() == Wbemcli.WBEM_S_NO_MORE_DATA) {\n                    break;\n                }\n                // Throw exception to notify user of timeout\n                if (hres.intValue() == Wbemcli.WBEM_S_TIMEDOUT) {\n                    throw new TimeoutException(\"No results after \" + timeout + \" ms.\");\n                }\n                // Other exceptions here.\n                if (COMUtils.FAILED(hres)) {\n                    throw new COMException(\"Failed to enumerate results.\", hres);\n                }\n\n                VARIANT.ByReference pVal = new VARIANT.ByReference();\n                IntByReference pType = new IntByReference();\n\n                // Get the value of the properties\n                IWbemClassObject clsObj = new IWbemClassObject(pclsObj[0]);\n                for (T property : propertyEnum.getEnumConstants()) {\n                    clsObj.Get(wstrMap.get(property), 0, pVal, pType, null);\n                    int vtType = (pVal.getValue() == null ? Variant.VT_NULL : pVal.getVarType()).intValue();\n                    int cimType = pType.getValue();\n                    switch (vtType) {\n                        case Variant.VT_BSTR:\n                            values.add(vtType, cimType, property, pVal.stringValue());\n                            break;\n                        case Variant.VT_I4:\n                            values.add(vtType, cimType, property, pVal.intValue());\n                            break;","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java#L293-L329","documentation":"In enumerateProperties, any HRESULT from IEnumWbemClassObject::Next that is not WBEM_S_FALSE / WBEM_S_NO_MORE_DATA / WBEM_S_TIMEDOUT and indicates failure (COMUtils.FAILED) produces this COMException, wrapping the HRESULT for diagnostics.","triggerScenarios":"The WMI enumerator returns a failing HRESULT — e.g. WBEM_E_FAILED, WBEM_E_INVALID_QUERY, WBEM_E_ACCESS_DENIED, or WBEM_E_NOT_SUPPORTED from the underlying provider — during Next().","commonSituations":"WMI repository corruption; provider-specific failures (e.g. corrupted performance counters for Win32_PerfFormattedData classes); permission problems on remote namespaces; WMI service throttling.","solutions":["Inspect the HRESULT inside the COMException (getHresult()) and match it against Wbemcli constants to find the specific cause.","Run winmgmt /verifyrepository and rebuild the WMI repository if corrupt.","Check permissions on the WMI namespace (e.g. wmimgmt.msc -> WMI Control -> Security).","Simplify the query and test with wbemtest or PowerShell Get-WmiObject to isolate provider failures."],"exampleFix":"// before\ntry { result = query.execute(); } catch (COMException e) { throw e; }\n// after\ntry {\n    result = query.execute();\n} catch (COMException e) {\n    log.error(\"WMI enumerate failed, hresult=0x{}\", Integer.toHexString(e.getHresult().intValue()), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    result = query.execute();\n} catch (COMException e) {\n    int hres = e.getHresult() != null ? e.getHresult().intValue() : -1;\n    switch (hres) {\n        case Wbemcli.WBEM_E_ACCESS_DENIED: /* fix namespace permissions */ break;\n        case Wbemcli.WBEM_E_INVALID_QUERY: /* fix WQL */ break;\n        default: /* repository/provider failure */\n    }\n}","preventionTips":["Log the wrapped HRESULT for every COMException","Validate WQL with wbemtest/PowerShell first","Check WMI namespace security for the invoking user"],"tags":["windows","wmi","jna","hresult"],"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"}