{"record":{"id":"777cca8883c342ba","repo":"java-native-access/jna","slug":"unadvise-interface-must-define-a-value-for-iid-via-the","errorCode":null,"errorMessage":"unadvise: Interface must define a value for iid via the ComInterface annotation","messagePattern":"unadvise: Interface must define a value for iid via the ComInterface annotation","errorType":"exception","errorClass":"com.sun.jna.platform.win32.COM.COMException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java","lineNumber":333,"sourceCode":"\n        } catch (RuntimeException e) {\n            // Do not rewrap COMException\n            if (e instanceof COMException) {\n                throw e;\n            } else {\n                throw new COMException(\"Error occured in advise when trying to connect the listener \" + comEventCallbackListener, e);\n            }\n        }\n    }\n\n    @Override\n    public void unadvise(Class<?> comEventCallbackInterface, final IComEventCallbackCookie cookie) throws COMException {\n        assert COMUtils.comIsInitialized() : \"COM not initialized\";\n\n        try {\n            ComInterface comInterfaceAnnotation = comEventCallbackInterface.getAnnotation(ComInterface.class);\n            if (null == comInterfaceAnnotation) {\n                throw new COMException(\n                        \"unadvise: Interface must define a value for iid via the ComInterface annotation\");\n            }\n            IID iid = this.getIID(comInterfaceAnnotation);\n\n            final ConnectionPoint rawCp = this.fetchRawConnectionPoint(iid);\n\n            HRESULT hr = rawCp.Unadvise(((ComEventCallbackCookie) cookie).getValue());\n\n            rawCp.Release();\n            COMUtils.checkRC(hr);\n\n        } catch (RuntimeException e) {\n            // Do not rewrap COMException\n            if (e instanceof COMException) {\n                throw e;\n            } else {\n                throw new COMException(\"Error occured in unadvise when trying to disconnect the listener from \" + this, e);\n            }","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java#L315-L351","documentation":"Thrown by ProxyObject.unadvise() when the event callback interface class lacks a @ComInterface annotation from which the IID can be read. Without the IID the library cannot locate the connection point from which to disconnect the cookie. Like the advise counterpart, it is a definition error in the interface class.","triggerScenarios":"Calling proxy.unadvise(listenerInterface, cookie) where listenerInterface has no @ComInterface annotation or an empty iid.","commonSituations":"unadvise called with a different (unannotated) interface class than the one used for advise; annotation removed during refactoring; using a generated subclass.","solutions":["Annotate the interface with @ComInterface(iid=\"{GUID}\") exactly as used in advise","Pass the same interface class used in the original advise() call","Store the interface class and cookie together so unadvise uses matching values"],"exampleFix":"// before\nproxy.unadvise(UnannotatedEvents.class, cookie);\n// after\n@ComInterface(iid=\"{00020902-0000-0000-C000-000000000046}\")\ninterface MyEvents extends IComEventCallbackListener { ... }\nproxy.unadvise(MyEvents.class, cookie);","handlingStrategy":"validation","validationCode":"if (!iface.isAnnotationPresent(ComInterface.class)) { throw new IllegalArgumentException(\"unadvise requires @ComInterface annotation\"); }","typeGuard":"boolean canUnadvise = (Class<?> c) -> c.isAnnotationPresent(ComInterface.class);","tryCatchPattern":"try { proxy.unadvise(iface, cookie); } catch (COMException e) { LOG.error(\"unadvise failed\", e); }","preventionTips":["Store the same interface class used in advise together with its cookie","Never remove @ComInterface from interfaces used with unadvise","Pair every advise with a finally-unadvise"],"tags":["com","annotation","iid","unadvise"],"backgroundTag":"missing-required-config-field","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"}