Skip to content

Commit b665e9e

Browse files
committed
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.
1 parent 0da700d commit b665e9e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Features
1010

1111
Bug Fixes
1212
---------
13-
13+
* [#1686](https://github.com/java-native-access/jna/issues/1686): Fix `sortFields` race condition while getting fields
1414

1515
Release 5.18.0
1616
==============

src/com/sun/jna/Structure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ private static <T extends Comparable<T>> List<T> sort(Collection<? extends T> c)
11251125
and can't be generated automatically.
11261126
**/
11271127
protected List<Field> getFields(boolean force) {
1128-
List<Field> flist = getFieldList();
1128+
List<Field> flist = new ArrayList<>(getFieldList());
11291129
Set<String> names = new HashSet<>();
11301130
for (Field f : flist) {
11311131
names.add(f.getName());

0 commit comments

Comments
 (0)