RFR: 8368729: Add appropriate checks in java.awt.image.Kernel constructor
Jayathirth D V
jdv at openjdk.org
Thu Nov 6 08:48:08 UTC 2025
On Wed, 5 Nov 2025 23:50:45 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> `java.awt.image.Kernel` constructor doesn't validate all input values and we need to add appropriate checks.
>> A new test is also added to make sure we appropriate exception when invalid values are passed.
>>
>> This will also need a CSR.
>
> src/java.desktop/share/classes/java/awt/image/Kernel.java line 62:
>
>> 60: * @param height height of the kernel
>> 61: * @param data kernel data in row major order
>> 62: * @throws IllegalArgumentException if {@code data} is null
>
> Is there any particular reason why IllegalArgumentException was chosen instead of NullPointerException?
Spec of NPE states multiple reasons of when an NPE is thrown while using null object and IAE clearly mentions that we are trying to validate input arguments and throw it when we see any issue.
Current spec already throws IAE in one of the validation scenario, so throwing the same IAE for other input argument validation is uniform.
We can say that in other parts of JDK we throw NPE for null argument verification, but using IAE in this scenario looks better.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28127#discussion_r2498039966
More information about the client-libs-dev
mailing list