RFR: 8361300: Document exceptions for Unsafe offset methods [v4]

Alan Bateman alanb at openjdk.org
Mon Jul 7 10:00:55 UTC 2025


On Thu, 3 Jul 2025 18:41:27 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Unsafe throws IAE for misusing static vs instance fields, and it's revealed that AtomicXxxFieldUpdaters are using this mechanism to reject static fields. This is not a good practice, but we can at least document this so we don't accidentally introduce problems.
>
> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Test to verify observed internal unsafe behaviors

src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java line 407:

> 405:             if (Modifier.isStatic(modifiers))
> 406:                 throw new IllegalArgumentException("Must not be a static field");
> 407: 

@viktorklang-ora @DougLea Should we update the Atomic*FieldUpdater to specify the IAE when the factory method is called with a static Field?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25945#discussion_r2189553083


More information about the core-libs-dev mailing list