[jdk21u-dev] RFR: 8335638: Calling VarHandle.{access-mode} methods reflectively throws wrong exception
Rui Li
duke at openjdk.org
Wed Sep 3 02:57:18 UTC 2025
A clean backport for https://bugs.openjdk.org/browse/JDK-8335638.
According to [the API specification](https://github.com/openjdk/jdk/blob/d7b941640638b35f9ac1ef11cd6bf6ccb795c29a/src/java.base/share/classes/java/lang/invoke/VarHandle.java#L435-L442), invoking VarHandle.{access-mode} methods reflectively throws an `UnsupportedOperationException`. However, it currently throws exception is an `UnsatisfiedLinkError` instead. (Pretty much what's in the `Problem` section of the [CSR](https://bugs.openjdk.org/browse/JDK-8335805))
Low risk. See Hannes Greule's comment in CSR: https://bugs.openjdk.org/browse/JDK-8335805:
> it only applies when invoking those methods reflectively - doing that always results in some form of Throwable being thrown - MethodHandle already throws UnsupportedOperationException in the same case - The exception is wrapped by an InvocationTargetException
Note: I'm not sure if there are any additional processes aside from a pr itself when backporting a fix requiring a CSR to previous versions. Let me know if it requires something else.
-------------
Commit messages:
- Backport 9fe6e2316aef8fd125a7905cff2a2d9ae5d26109
Changes: https://git.openjdk.org/jdk21u-dev/pull/2144/files
Webrev: https://webrevs.openjdk.org/?repo=jdk21u-dev&pr=2144&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8335638
Stats: 77 lines in 2 files changed: 72 ins; 0 del; 5 mod
Patch: https://git.openjdk.org/jdk21u-dev/pull/2144.diff
Fetch: git fetch https://git.openjdk.org/jdk21u-dev.git pull/2144/head:pull/2144
PR: https://git.openjdk.org/jdk21u-dev/pull/2144
More information about the jdk-updates-dev
mailing list