From b665e9e6a2752aba2dcb9a73b00c086a5122f595 Mon Sep 17 00:00:00 2001 From: Ben Dean-Kawamura Date: Fri, 26 Sep 2025 11:58:26 -0400 Subject: [PATCH] Avoid threading issues in sortFields (#1686) Copy the fields array from `getFieldList`, this avoids the possibility of 2 threads trying to mutate it at once in the call `sortFields` at the bottom of the function. --- CHANGES.md | 2 +- src/com/sun/jna/Structure.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9b149a2da..12193a152 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,7 @@ Features Bug Fixes --------- - +* [#1686](https://github.com/java-native-access/jna/issues/1686): Fix `sortFields` race condition while getting fields Release 5.18.0 ============== diff --git a/src/com/sun/jna/Structure.java b/src/com/sun/jna/Structure.java index 12e03f7fa..6a7d0c4df 100644 --- a/src/com/sun/jna/Structure.java +++ b/src/com/sun/jna/Structure.java @@ -1125,7 +1125,7 @@ private static > List sort(Collection c) and can't be generated automatically. **/ protected List getFields(boolean force) { - List flist = getFieldList(); + List flist = new ArrayList<>(getFieldList()); Set names = new HashSet<>(); for (Field f : flist) { names.add(f.getName());