From 843fc08ffd8e2c3bf03c2ff96e33fad5c1e37a28 Mon Sep 17 00:00:00 2001 From: Laszlo Kishalmi Date: Sun, 12 Nov 2023 16:18:08 -0800 Subject: [PATCH] Fix ConcurrentModificationException in TestMethodController --- .../modules/gsf/testrunner/ui/api/TestMethodController.java | 6 ++---- .../modules/java/testrunner/ui/ComputeTestMethodsImpl.java | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/api/TestMethodController.java b/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/api/TestMethodController.java index aa8b742a6e3a..85e064ee7d4d 100644 --- a/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/api/TestMethodController.java +++ b/ide/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/api/TestMethodController.java @@ -62,12 +62,10 @@ private static void setTestMethodsImpl(StyledDocument doc, List meth doc.putProperty(TestMethodAnnotation.DOCUMENT_ANNOTATION_LINES_KEY, annotationLines); } - Map removed = new HashMap<>(annotations); - - methods.forEach(tm -> removed.remove(tm)); - Set added = new HashSet<>(methods); + Map removed = new HashMap<>(annotations); + removed.keySet().removeAll(added); added.removeAll(annotations.keySet()); for (TestMethod method : added) { diff --git a/java/java.testrunner.ui/src/org/netbeans/modules/java/testrunner/ui/ComputeTestMethodsImpl.java b/java/java.testrunner.ui/src/org/netbeans/modules/java/testrunner/ui/ComputeTestMethodsImpl.java index 6236049250e0..847e203f158e 100644 --- a/java/java.testrunner.ui/src/org/netbeans/modules/java/testrunner/ui/ComputeTestMethodsImpl.java +++ b/java/java.testrunner.ui/src/org/netbeans/modules/java/testrunner/ui/ComputeTestMethodsImpl.java @@ -103,7 +103,8 @@ public void run(CompilationInfo info) throws Exception { } if (!cancel.get()) { - WORKER.post(() -> TestMethodController.setTestMethods(doc, methods)); + List updateMethods = new ArrayList<>(methods); + WORKER.post(() -> TestMethodController.setTestMethods(doc, updateMethods)); } } }