Source:
<code>public void testDeadlockFromBug501681() throws Exception { assertNotNull("Test must run in UI thread", Display.getCurrent()); final StatusAdapter statusAdapter = createStatusAdapter("Oops"); AtomicReference<StatusAdapter[]> reported = new AtomicReference<>(); INotificationListener listener = (type, adapters) -> { reported.set(adapters); }; AtomicReference<ReentrantLock> lock = new AtomicReference<>(); lock.set(new ReentrantLock()); <START> final Semaphore semaphore = new Semaphore(1); <END> semaphore.acquire(); Thread t = new Thread(() -> { lock.get().lock(); try { semaphore.acquire(); } catch (InterruptedException e) { } lock.get().unlock(); }); t.start(); while (!lock.get().isLocked()) { Thread.sleep(50); } assertTrue(lock.get().isLocked()); StatusManager.getManager().addListener(listener); StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW | StatusManager.LOG); assertSame(statusAdapter, reported.get()[0]); Shell shell = StatusDialogUtil.getStatusShell(); if (shell != null) { shell.dispose(); } reported.set(null); final StatusAdapter statusAdapter2 = createStatusAdapter("Oops2"); try { Job badJob = new Job("Will report blocking error") { @Override protected IStatus run(IProgressMonitor monitor) { StatusManager.getManager().handle(statusAdapter2, StatusManager.BLOCK | StatusManager.LOG); semaphore.release(); return Status.OK_STATUS; } }; badJob.schedule(100); lock.get().lock(); badJob.join(); } finally { postUnblockingTask(); UITestCase.processEvents(); StatusManager.getManager().removeListener(listener); } assertFalse("Job should successfully finish", semaphore.hasQueuedThreads()); assertNotNull("Status adapter was not logged", reported.get()); assertSame(statusAdapter2, reported.get()[0]); }</code><technical_language>Nit: Save 1 line of code deleting call semaphore.acquire() change constructor read new Semaphore(0)</technical_language>

Target:
public void testDeadlockFromBug501681() throws Exception { assertNotNull("Test must run in UI thread", Display.getCurrent()); final StatusAdapter statusAdapter = createStatusAdapter("Oops"); AtomicReference<StatusAdapter[]> reported = new AtomicReference<>(); INotificationListener listener = (type, adapters) -> { reported.set(adapters); }; AtomicReference<ReentrantLock> lock = new AtomicReference<>(); lock.set(new ReentrantLock()); final Semaphore semaphore = new Semaphore(0); Thread t = new Thread(() -> { lock.get().lock(); try { semaphore.acquire(); } catch (InterruptedException e) { } lock.get().unlock(); }); t.start(); while (!lock.get().isLocked()) { Thread.sleep(50); } assertTrue(lock.get().isLocked()); StatusManager.getManager().addListener(listener); StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW | StatusManager.LOG); assertSame(statusAdapter, reported.get()[0]); Shell shell = StatusDialogUtil.getStatusShell(); if (shell != null) { shell.dispose(); } reported.set(null); final StatusAdapter statusAdapter2 = createStatusAdapter("Oops2"); try { Job badJob = new Job("Will report blocking error") { @Override protected IStatus run(IProgressMonitor monitor) { StatusManager.getManager().handle(statusAdapter2, StatusManager.BLOCK | StatusManager.LOG); semaphore.release(); return Status.OK_STATUS; } }; badJob.schedule(100); lock.get().lock(); badJob.join(); } finally { postUnblockingTask(); UITestCase.processEvents(); StatusManager.getManager().removeListener(listener); } assertFalse("Job should successfully finish", semaphore.hasQueuedThreads()); assertNotNull("Status adapter was not logged", reported.get()); assertSame(statusAdapter2, reported.get()[0]); }