Integrated: JDK-8277451: java.lang.reflect.Field::set on static field with invalid argument type should throw IAE

Mandy Chung mchung at openjdk.java.net
Tue Nov 23 17:18:14 UTC 2021


On Sat, 20 Nov 2021 19:13:43 GMT, Mandy Chung <mchung at openjdk.org> wrote:

> java.lang.reflect.Field::set on static field with invalid argument type should throw IAE.  But this regression is introduced by JEP 416 throwing NPE instead.
> 
> `ensureObj` is called as the first check of the `Field::set` method to ensure the receiver object is checked first before the argument.   For a Field instance with write-access, the method handle invocation will check the receiver.  Therefore for `Field::setXXX` methods to set a primitive value, `ensureObj` is only called if it's a read-only Field instance to ensure IllegalArgumentException is thrown first before IllegalAccessException to keep the existing behavior to avoid duplicated receiver check.

This pull request has now been integrated.

Changeset: 03206726
Author:    Mandy Chung <mchung at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/032067264fd73cd2f338838d6178f8af24d228b0
Stats:     691 lines in 13 files changed: 637 ins; 27 del; 27 mod

8277451: java.lang.reflect.Field::set on static field with invalid argument type should throw IAE

Reviewed-by: alanb

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

PR: https://git.openjdk.java.net/jdk/pull/6490


More information about the core-libs-dev mailing list