diff --git a/src/main/java/spoon/support/adaption/TypeAdaptor.java b/src/main/java/spoon/support/adaption/TypeAdaptor.java index 34bac74c489..a214df4a334 100644 --- a/src/main/java/spoon/support/adaption/TypeAdaptor.java +++ b/src/main/java/spoon/support/adaption/TypeAdaptor.java @@ -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) { + 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);