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

Mandy Chung mchung at openjdk.java.net
Mon Nov 22 20:01:50 UTC 2021


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

Mandy Chung has updated the pull request incrementally with one additional commit since the last revision:

  Improve the exception message when the type is not available

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/6490/files
  - new: https://git.openjdk.java.net/jdk/pull/6490/files/1c679d7a..63134634

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=6490&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=6490&range=00-01

  Stats: 27 lines in 2 files changed: 14 ins; 10 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6490.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6490/head:pull/6490

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


More information about the core-libs-dev mailing list