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

Joe Darcy darcy at openjdk.org
Wed Nov 9 21:38:32 UTC 2022


On Wed, 9 Nov 2022 10:14:45 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> 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

Looks fine.

It is fine to use an old class file version, but I think using a new one would be fine too.

I don't know if using junit here pulls its weight.

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

Marked as reviewed by darcy (Reviewer).

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


More information about the core-libs-dev mailing list