On Fri, 31 Jul 2026 04:05:28 GMT, Chen Liang <[email protected]> wrote:

> The static field VarHandle is missing null checks that blocks incoming nulls.
> 
> The fix is simple; the overwhelming changes come from these areas:
> 1. To introduce a null-restricted set of fields and values, we need to use 
> early initialization and null-restricted array creation for our test 
> templates.
> 2. Added `test(InstanceField|StaticField|Array)NullPointerException` to 
> `VarHandleTest(MethodHandle|)AccessNullRestrictedValue` for the effective 
> unit tests. Without the patch, the `testStaticFieldNullPointerException` 
> fails.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Reviewed. Suggestions are inline.

_— qwen3.8-max-preview via Qwen Code /review_

test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessNullRestrictedValue.java
 line 696:

> 694:             {
> 695:                 boolean success = (boolean) 
> hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 
> NullRestrictedValue.of((byte)20,(short)1854), 
> NullRestrictedValue.of((byte)20,(short)-31083));
> 696:                 assertEquals(success, false, "failing 
> weakCompareAndSetAcquire NullRestrictedValue");

**[Suggestion]** Copy-paste error: the failing case after the 
`WEAK_COMPARE_AND_SET_RELEASE` success block uses 
`WEAK_COMPARE_AND_SET_ACQUIRE` instead of `WEAK_COMPARE_AND_SET_RELEASE`, 
leaving the RELEASE failing path untested for arrays. The root cause is in the 
template `X-VarHandleTestMethodHandleAccess.java.template` (array section, line 
~984) — fixing only this generated file without fixing the template would cause 
the bug to reappear on regeneration. — Concrete cost: if a regression made 
`weakCompareAndSetRelease` on an array incorrectly succeed with a mismatched 
expected value, this test would not catch it.

Suggestion:

                boolean success = (boolean) 
hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 
NullRestrictedValue.of((byte)20,(short)1854), 
NullRestrictedValue.of((byte)20,(short)-31083));
                assertEquals(success, false, "failing weakCompareAndSetRelease 
NullRestrictedValue");


_— qwen3.8-max-preview via Qwen Code /review_

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

PR Review: https://git.openjdk.org/jdk/pull/32115#pullrequestreview-4833706477
PR Review Comment: https://git.openjdk.org/jdk/pull/32115#discussion_r3694647280

Reply via email to