diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java index e52df2103..135ae1641 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java @@ -37,6 +37,8 @@ /** Provides a mocking framework for the extension point registry. */ public final class ExtensionRegistryMock { + private static final Object LOCK = new Object(); + private static IExtensionRegistry registry; private static IExtensionRegistry registrySpy; private static Multimap configurationElements = LinkedHashMultimap.create(); @@ -52,18 +54,20 @@ private ExtensionRegistryMock() { * if the registry provider cannot be set */ @SuppressWarnings("restriction") // for accessing RegistryProviderFactory - public static synchronized void mockRegistry() { - if (registrySpy == null) { - registry = RegistryFactory.getRegistry(); - registrySpy = spy(registry); - org.eclipse.core.internal.registry.RegistryProviderFactory.releaseDefault(); - try { - RegistryFactory.setDefaultRegistryProvider(() -> { - return registrySpy; - }); - } catch (CoreException e) { - // This shouldn't happen as the default was released. - throw new WrappedException(e); + public static void mockRegistry() { + synchronized (LOCK) { + if (registrySpy == null) { + registry = RegistryFactory.getRegistry(); + registrySpy = spy(registry); + org.eclipse.core.internal.registry.RegistryProviderFactory.releaseDefault(); + try { + RegistryFactory.setDefaultRegistryProvider(() -> { + return registrySpy; + }); + } catch (CoreException e) { + // This shouldn't happen as the default was released. + throw new WrappedException(e); + } } } } diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java index 3389a0348..ba30e1009 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java @@ -134,6 +134,8 @@ public String toString() { } + private final Object lock = new Object(); + private final JobFinder finder; private final long waitTimeout; @@ -183,17 +185,19 @@ public static JobMatcher registerNewJobByFamilyMatcher(final Object family) { * * @return the list of matching existing jobs */ - public final synchronized List register() { - newJobs = Collections.synchronizedList(Lists. newArrayList()); - jobQueue = new LinkedBlockingQueue(); - Job.getJobManager().addJobChangeListener(this); + public final List register() { + synchronized (lock) { + newJobs = Collections.synchronizedList(Lists. newArrayList()); + jobQueue = new LinkedBlockingQueue(); + Job.getJobManager().addJobChangeListener(this); - // save list of existing jobs *after* adding job listener (in case jobs finish in the mean time) - existingJobs = ImmutableList.copyOf(finder.find()); - finishedJobs = Collections.synchronizedList(Lists. newArrayList()); - timeout = System.currentTimeMillis() + waitTimeout; + // save list of existing jobs *after* adding job listener (in case jobs finish in the mean time) + existingJobs = ImmutableList.copyOf(finder.find()); + finishedJobs = Collections.synchronizedList(Lists. newArrayList()); + timeout = System.currentTimeMillis() + waitTimeout; - return ImmutableList.copyOf(existingJobs); + return ImmutableList.copyOf(existingJobs); + } } /** @@ -290,18 +294,22 @@ private Job getNextJob() throws InterruptedException { } @Override - public synchronized void scheduled(final IJobChangeEvent event) { - Job job = event.getJob(); - if (finder.apply(job)) { - newJobs.add(job); + public void scheduled(final IJobChangeEvent event) { + synchronized (lock) { + Job job = event.getJob(); + if (finder.apply(job)) { + newJobs.add(job); + } } } @Override - public synchronized void done(final IJobChangeEvent event) { - Job job = event.getJob(); - if (finder.apply(job)) { - jobQueue.add(job); + public void done(final IJobChangeEvent event) { + synchronized (lock) { + Job job = event.getJob(); + if (finder.apply(job)) { + jobQueue.add(job); + } } } } diff --git a/ddk-configuration/findbugs/exclusion-filter.xml b/ddk-configuration/findbugs/exclusion-filter.xml index 00384ace0..1f6613875 100644 --- a/ddk-configuration/findbugs/exclusion-filter.xml +++ b/ddk-configuration/findbugs/exclusion-filter.xml @@ -75,4 +75,8 @@ + + + +