[lworld] RFR: 8349945: Implement strict static fields (proposed JVM feature) [v3]

Matias Saavedra Silva matsaave at openjdk.org
Thu May 29 16:56:12 UTC 2025


On Mon, 26 May 2025 15:34:45 GMT, Dan Heidinga <heidinga at openjdk.org> wrote:

> > I think reflective write for static final is already impossible - at least that is what I know about Method Handles and core reflection. So we probably just need to care about reflective reads.
> 
> Let's confirm that. It used to be possible (and maybe still is) to use `setAccessible` to allow reflective writes to finals. MHs won't unallow static final setters unless they come through the MethodHandles::unreflect door with an `accessible` reflective field

It looks like Chen is correct here, reflective writing of static finals doesn't seem to be possible. At the very least, setAccessible() won't prevent an exception like this:
`java.lang.IllegalAccessException: Can not set static final java.lang.String field WriteAfterReadRefl1.F1__STRICT to java.lang.String`

With regards to your suggested test cases, the best I can do at the moment is add the first one on that list.

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

PR Comment: https://git.openjdk.org/valhalla/pull/1465#issuecomment-2919999720


More information about the valhalla-dev mailing list