On Tue, 25 Nov 2025 02:52:33 GMT, Steve Armstrong <[email protected]> wrote:
>> The three AtomicXxxFieldUpdater classes (AtomicIntegerFieldUpdater, >> AtomicLongFieldUpdater, and AtomicReferenceFieldUpdater) contain duplicate >> field validation and access checking logic in their constructors and helper >> methods. >> >> This change extracts the common validation and utility methods into a new >> package-private class FieldUpdaterUtil to eliminate code duplication and >> improve maintainability. >> >> Changes: >> - Added new FieldUpdaterUtil class with static utility methods: >> * validateField() - validates field type, volatile, and static checks >> * computeAccessClass() - determines correct class for access checks >> * isSamePackage() - checks if two classes are in same package >> * isAncestor() - checks classloader delegation chain >> >> - Updated AtomicIntegerFieldUpdater to use FieldUpdaterUtil >> * Simplified constructor to use validateField() and computeAccessClass() >> * Removed duplicate isAncestor() and isSamePackage() methods >> >> - Updated AtomicLongFieldUpdater to use FieldUpdaterUtil >> * Simplified constructor to use validateField() and computeAccessClass() >> * Removed duplicate isAncestor() and isSamePackage() methods >> >> - Updated AtomicReferenceFieldUpdater to use FieldUpdaterUtil >> * Simplified constructor to use validateField() and computeAccessClass() >> * Removed duplicate isAncestor() and isSamePackage() methods >> >> Existing tests in test/jdk/java/util/concurrent/tck and >> test/jdk/java/util/concurrent/atomic verify that the refactoring preserves >> the original behavior. > > Steve Armstrong has updated the pull request incrementally with one > additional commit since the last revision: > > Replace legacy ReflectUtil with modern Reflection API > > Replaced sun.reflect.misc.ReflectUtil with jdk.internal.reflect.Reflection > in atomic field updaters. Added getFieldWithAccess() method and > FieldAndModifiers record to FieldUpdaterUtil to consolidate field > access checking logic. Changes requested by liach (Reviewer). src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java line 391: > 389: FieldUpdaterUtil.FieldAndModifiers fam = > 390: FieldUpdaterUtil.getFieldWithAccess(tclass, fieldName, > caller); > 391: FieldUpdaterUtil.validateField(fam.field, int.class); Consider using this code sequence: Field field = FieldUpdaterUtil.findValidatedField(tclass, fieldName, caller, int.class); this.cclass = FieldUpdaterUtil.computeAccessClass(tclass, caller, field.getModifiers()); this.tclass = tclass; this.offset = U.objectFieldOffset(field); ------------- PR Review: https://git.openjdk.org/jdk/pull/28464#pullrequestreview-3503100202 PR Review Comment: https://git.openjdk.org/jdk/pull/28464#discussion_r2558406263
