Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add thread-safety to TypeAdaptor method adaptation
Browse files Browse the repository at this point in the history
Synchronization logic has been added to the method adaptation process in the TypeAdaptor class to prevent multi-threading issues. This change was necessary because without synchronization, simultaneous modifications by multiple threads could lead to inconsistent or unexpected results. The relevant issue can be found at #5619.
MartinWitt committed Jan 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f2077c5 commit 1eb34e2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/spoon/support/adaption/TypeAdaptor.java
Original file line number Diff line number Diff line change
@@ -450,13 +450,17 @@ public boolean isOverriding(CtMethod<?> subMethod, CtMethod<?> superMethod) {
if (!isSubtype(subDeclaringType, superDeclaringType.getReference())) {
return false;
}

// we lock here because of multi threading issues, see https://github.com/INRIA/spoon/issues/5619
CtMethod<?> adapted;
// We don't need to clone the body here, so leave it out
CtBlock<?> superBody = superMethod.getBody();
superMethod.setBody(null);
CtMethod<?> adapted = new TypeAdaptor(subMethod.getDeclaringType())
.adaptMethod(superMethod);
superMethod.setBody(superBody);
synchronized (superMethod) {

Check warning on line 456 in src/main/java/spoon/support/adaption/TypeAdaptor.java

GitHub Actions / Qodana Community for JVM

Synchronization on local variable or method parameter

Synchronization on method parameter `superMethod`
CtBlock<?> superBody = superMethod.getBody();
superBody.clone();
superMethod.setBody(null);
adapted = new TypeAdaptor(subMethod.getDeclaringType())
.adaptMethod(superMethod);
superMethod.setBody(superBody);
}

for (int i = 0; i < subMethod.getParameters().size(); i++) {
CtParameter<?> subParam = subMethod.getParameters().get(i);

0 comments on commit 1eb34e2

Please sign in to comment.