On Tue, 24 Jun 2025 00:04:54 GMT, Chen Liang <li...@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.

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

> 415:                           ? caller : tclass;
> 416:             this.tclass = tclass;
> 417:             this.offset = U.objectFieldOffset(field); // throws IAE for 
> static

AtomicIntegerFieldUpdaterImpl already checks the field type and it is volatile. 
I think it would be better to expand these checks so that static volatile 
fields are rejected there rather than "accidentally" calling objectFieldOffset 
with a static field.

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

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

Reply via email to