RFR: 8374113: Taughtological if check in Reflection::array_set

Chen Liang liach at openjdk.org
Fri Dec 19 15:51:15 UTC 2025


On Fri, 19 Dec 2025 10:32:43 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

> While reviewing code in the Valhalla repository I saw that Reflection::array_set has this funny-looking code:
> 
>   if (a->is_objArray()) {
>     if (value_type == T_OBJECT) {
>     ...
>     } // what happens in the else case? here
>   } else {
>     assert(a->is_typeArray(), "just checking");
>   }
> 
> And wondered what would happen if the `value_type == T_OBJECT` check failed, and how is this handled with flattened arrays, given that we have T_FLAT_ELEMENT there.
> 
> It turns out that the calling code passes down T_OBJECT even for flat arrays so they do take the `value_type == T_OBJECT` path, so that's fine.
> 
> So, I propose that we just replace one of the ifs with an assert.

This one seems safe because this seems only used by `Array.set` and the primitive overloads.  I checked `JVM_SetArrayElement` and `JVM_SetPrimitiveArrayElement` callers in `Array.c`. However note that `java.lang.reflect.Array` is poorly tested/covered, so please help check if there are other sites that can pass in inconsistent array oop + value type.

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

PR Comment: https://git.openjdk.org/jdk/pull/28921#issuecomment-3675557830


More information about the hotspot-runtime-dev mailing list