[jdk21u-dev] RFR: 8335638: Calling VarHandle.{access-mode} methods reflectively throws wrong exception

Severin Gehwolf sgehwolf at openjdk.org
Wed Sep 10 14:29:27 UTC 2025


On Wed, 3 Sep 2025 02:52:36 GMT, Rui Li <duke at openjdk.org> wrote:

> 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.

This doesn't need to be backported to 21u. Users who need it should adopt JDK 25 quickly. JDK 24 with the patch is already out.

-------------

PR Comment: https://git.openjdk.org/jdk21u-dev/pull/2144#issuecomment-3275232909


More information about the jdk-updates-dev mailing list