Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in TestRunSession#toString and use AtomicReference #1213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.unittest.internal.UnitTestPlugin;
import org.eclipse.unittest.internal.launcher.TestViewSupportRegistry;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class TestRunSession extends TestSuiteElement implements ITestRunSession,
*/
private HashMap<String, TestElement> fIdToTest;

volatile Instant fStartTime;
private final AtomicReference<Instant> fStartTime = new AtomicReference<>();
volatile Integer fPredefinedTestCount;

volatile boolean fIsAborted;
Expand All @@ -105,7 +106,7 @@ public TestRunSession(String testRunName, Instant startTime, ILaunchConfiguratio
fIdToTest = new HashMap<>();

fTestRunnerClient = null;
fStartTime = startTime;
fStartTime.set(startTime);

fSessionListeners = new ListenerList<>();
}
Expand Down Expand Up @@ -254,7 +255,7 @@ public int getCurrentIgnoredCount() {
* @return an {@link Instant} object indicating a test run session start time
*/
public Instant getStartTime() {
return fStartTime;
return fStartTime.get();
}

/**
Expand All @@ -273,7 +274,7 @@ public boolean isStopped() {
*
* @param listener an {@link ITestSessionListener} object
*/
public synchronized void addTestSessionListener(ITestSessionListener listener) {
public void addTestSessionListener(ITestSessionListener listener) {
fSessionListeners.add(listener);
}

Expand Down Expand Up @@ -381,7 +382,8 @@ private class TestSessionNotifier {
* @param testCount number of tests in this run
*/
public void testRunStarted(Integer testCount) {
fStartTime = Instant.now();
// only update if not already set!
fStartTime.compareAndSet(null, Instant.now());
fPredefinedTestCount = testCount;

for (ITestSessionListener listener : fSessionListeners) {
Expand Down Expand Up @@ -590,7 +592,12 @@ private void addFailures(Collection<TestElement> failures, TestElement testEleme

@Override
public String toString() {
return fTestRunName + " " + DateFormat.getDateTimeInstance().format(new Date(fStartTime.toEpochMilli())); //$NON-NLS-1$
Instant startTime = getStartTime();
if (startTime == null) {
return fTestRunName + " (not started)"; //$NON-NLS-1$
} else {
return fTestRunName + " " + DateFormat.getDateTimeInstance().format(new Date(startTime.toEpochMilli())); //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move outside else

}
}

@Override
Expand Down
Loading