RFR: 8296196: `Class.getEnumConstants()` throws undocumented `ClassCastException` and `NullPointerException`

Adam Sotona asotona at openjdk.org
Wed Nov 9 10:20:23 UTC 2022


When `Class.getEnumConstants()` is called on a bad enum class where `values()` is an instance method, or returns a non‑array, then it throws `NullPointerException` or `ClassCastException` respectively. 

This patch fixes `Class.getEnumConstants()` method to handle above mentioned bad enums and adds relevant tests.

Please review.

Thanks,
Adam

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

Commit messages:
 - 8296196: Class.getEnumConstants() throws undocumented ClassCastException and NullPointerException

Changes: https://git.openjdk.org/jdk/pull/11056/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11056&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8296196
  Stats: 119 lines in 4 files changed: 118 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/11056.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11056/head:pull/11056

PR: https://git.openjdk.org/jdk/pull/11056


More information about the core-libs-dev mailing list