{"record":{"id":"9119ce8313dd2e45","repo":"java-native-access/jna","slug":"failed-to-call-addsuppressedmethod","errorCode":null,"errorMessage":"Failed to call addSuppressedMethod","messagePattern":"Failed to call addSuppressedMethod","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java","lineNumber":96,"sourceCode":"    static {\n        try {\n            addSuppressedMethod = Throwable.class.getMethod(\"addSuppressed\", Throwable.class);\n        } catch (NoSuchMethodException ex) {\n            // This is the case for JDK < 7\n        } catch (SecurityException ex) {\n            Logger.getLogger(Win32Exception.class.getName()).log(Level.SEVERE, \"Failed to initialize 'addSuppressed' method\", ex);\n        }\n    }\n\n    void addSuppressedReflected(Throwable exception) {\n        if(addSuppressedMethod == null) {\n            // Make this a NOOP on an unsupported JDK\n            return;\n        }\n        try {\n            addSuppressedMethod.invoke(this, exception);\n        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {\n            throw new RuntimeException(\"Failed to call addSuppressedMethod\", ex);\n        }\n    }\n}\n","sourceCodeStart":78,"sourceCodeEnd":100,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java#L78-L100","documentation":"Win32Exception.addSuppressedReflected() attaches a suppressed exception via a reflectively-obtained Throwable.addSuppressed method (a NOOP on JDKs without it). If the reflective invocation itself fails (illegal access, bad arguments, or the target threw), the library wraps the failure in this RuntimeException. It signals reflection plumbing broke, usually not a user data problem.","triggerScenarios":"Calling addSuppressedReflected (directly or via paths like getCurrentUserGroups, accessCheck, cryptProtectData/cryptUnprotectData, getScreenshot, closeHandleRefs) on a JVM where the cached addSuppressed Method handle cannot be invoked — e.g. a security manager denying reflective access, or a JDK where the method signature lookup mismatches.","commonSituations":"Running under a strict SecurityManager or module restrictions (JPMS strong encapsulation); exotic/very old JVMs the reflection check misclassified; bytecode/repackage environments (certain shaded/Android-like runtimes).","solutions":["Upgrade to a supported standard JDK so addSuppressed resolves and invokes normally.","Remove SecurityManager / reflective-access restrictions for the library's packages (add-opens if needed).","Catch the RuntimeException and log it — the original Win32Exception is still valid and usable.","Ensure the library version matches the target JDK line (re-check the addSuppressed NOOP guard)."],"exampleFix":"// before\nex.addSuppressedReflected(suppressed); // may throw\n// after\ntry {\n    ex.addSuppressedReflected(suppressed);\n} catch (RuntimeException reflectionFailure) {\n    logger.warning(\"could not attach suppressed: \" + reflectionFailure);\n}","handlingStrategy":"try-catch","validationCode":"// check JVM supports reflective addSuppressed before use\nMethod m = Throwable.class.getMethod(\"addSuppressed\", Throwable.class);\nm.setAccessible(true); // throws if access is denied -> environment will fail","typeGuard":null,"tryCatchPattern":"try {\n    ex.addSuppressedReflected(suppressed);\n} catch (RuntimeException e) {\n    logger.warning(\"addSuppressed failed; original exception still usable\", e);\n}","preventionTips":["Run on supported JDKs without restrictive SecurityManagers.","Use --add-opens for encapsulated packages when running on modern JDKs.","Treat suppressed-attachment as best-effort, never critical-path."],"tags":["windows","jna","reflection"],"backgroundTag":"internal-invariant-violation","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"}