Subject: [pgjdbc/pgjdbc] PR #3962: fix: catch SecurityException from setContextClassLoader on ForkJoinPool workers

From: "vlsi (@vlsi)" <[email-masked]>
Date: Sat, 14 Mar 2026 06:45:06 +0000

`InnocuousForkJoinWorkerThread` (used by `ForkJoinPool.commonPool()` under certain security configurations) throws `SecurityException` when `setContextClassLoader` is called. This crashed the cleanup thread, disabling phantom-reference-based leak detection for the rest of the JVM lifetime.
    
Wrap the call in try-catch since it is best-effort: `ForkJoinPool` does not inherit `contextClassLoader` from the submitting thread, but custom thread factories might, so we still attempt to nullify it.
    
Fixes https://github.com/pgjdbc/pgjdbc/issues/3953

---

From: "vlsi (@vlsi)" <[email-masked]>
Date: Sat, 14 Mar 2026 09:51:41 +0000

I couldn't make the test run with the SecurityManager as Gradle overrides it.