Missing throws declaration for NullPointerException in Proxy#getInvocationHandler
Kevin Bourrillion
kevin.bourrillion at oracle.com
Thu May 22 20:33:15 UTC 2025
I think Steffen is almost certainly right that this was an accidental omission. That omission results in the `@throws IAE` line being *interpreted* as also applying to null, but I doubt it was ever meant that way.
I think adding a `@throws NPE` is the right fix, and makes the class more consistent, and also preserves the ability to migrate the argument type to `Object!` in the future.
On May 22, 2025, at 1:06 PM, Chen Liang <chen.l.liang at oracle.com> wrote:
Hello, I have created https://bugs.openjdk.org/browse/JDK-8357597 for this.
Your analysis isn't quite correct - if you look at the method documentation, you would anticipate this to fail with an IllegalArgumentException instead of a NullPointerException. However, this mismatch has been there since 2006, so it's best to update the docs to match the actual longstanding behavior.
P.S. In the future, you can also report bugs via https://bugs.java.com/
Regard, Chen
________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Steffen Nießing <zuniquex at protonmail.com>
Sent: Thursday, May 22, 2025 1:12 PM
To: core-libs-dev at openjdk.org <core-libs-dev at openjdk.org>
Subject: Missing throws declaration for NullPointerException in Proxy#getInvocationHandler
Hi,
recently I've come across the documentation of Proxy#getInvocationHandler(Object) and recognized that there's a missing throws declaration for a NullPointerException. The expression Proxy.getInvocationHandler(null) fails, because proxy.getClass() is called without asserting that proxy is not null.
I'd be happy to provide the JavaDoc update, if anyone would like to sponsor me the JBS issue for this one.
Cheers
Steffen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250522/53f66669/attachment-0001.htm>
More information about the core-libs-dev
mailing list