1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Fix for java.util.ConcurrentModificationException

at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
	at java.util.AbstractList$Itr.next(Unknown Source)
	at org.eclipse.cdt.core.testplugin.util.BaseTestCase.runBare(BaseTestCase.java:166)
This commit is contained in:
Andrew Gvozdev 2012-04-14 20:40:59 -04:00
parent fce6b5a258
commit 0e563742a1

View file

@ -8,7 +8,7 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin.util; package org.eclipse.cdt.core.testplugin.util;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -48,11 +48,11 @@ public class BaseTestCase extends TestCase {
private boolean fExpectFailure; private boolean fExpectFailure;
private int fBugNumber; private int fBugNumber;
private int fExpectedLoggedNonOK; private int fExpectedLoggedNonOK;
public BaseTestCase() { public BaseTestCase() {
super(); super();
} }
public BaseTestCase(String name) { public BaseTestCase(String name) {
super(name); super(name);
} }
@ -67,7 +67,7 @@ public class BaseTestCase extends TestCase {
CPPASTNameBase.sAllowNameComputation= false; CPPASTNameBase.sAllowNameComputation= false;
CModelListener.sSuppressUpdateOfLastRecentlyUsed= true; CModelListener.sSuppressUpdateOfLastRecentlyUsed= true;
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
ResourceHelper.cleanUp(); ResourceHelper.cleanUp();
@ -77,7 +77,7 @@ public class BaseTestCase extends TestCase {
protected static TestSuite suite(Class clazz) { protected static TestSuite suite(Class clazz) {
return suite(clazz, null); return suite(clazz, null);
} }
protected static TestSuite suite(Class clazz, String failingTestPrefix) { protected static TestSuite suite(Class clazz, String failingTestPrefix) {
TestSuite suite= new TestSuite(clazz); TestSuite suite= new TestSuite(clazz);
Test failing= getFailingTests(clazz, failingTestPrefix); Test failing= getFailingTests(clazz, failingTestPrefix);
@ -149,7 +149,7 @@ public class BaseTestCase extends TestCase {
if (corePlugin != null) { // if we don't run a JUnit Plugin Test if (corePlugin != null) { // if we don't run a JUnit Plugin Test
corePlugin.getLog().addLogListener(logListener); corePlugin.getLog().addLogListener(logListener);
} }
Throwable testThrowable= null; Throwable testThrowable= null;
try { try {
try { try {
@ -157,25 +157,27 @@ public class BaseTestCase extends TestCase {
} catch (Throwable e) { } catch (Throwable e) {
testThrowable=e; testThrowable=e;
} }
if (statusLog.size() != fExpectedLoggedNonOK) { if (statusLog.size() != fExpectedLoggedNonOK) {
StringBuffer msg= new StringBuffer("Expected number (" + fExpectedLoggedNonOK + ") of "); StringBuffer msg= new StringBuffer("Expected number (" + fExpectedLoggedNonOK + ") of ");
msg.append("non-OK status objects in log differs from actual (" + statusLog.size() + ").\n"); msg.append("non-OK status objects in log differs from actual (" + statusLog.size() + ").\n");
Throwable cause= null; Throwable cause= null;
if (!statusLog.isEmpty()) { if (!statusLog.isEmpty()) {
for (IStatus status : statusLog) { synchronized(statusLog) {
IStatus[] ss= {status}; for (IStatus status : statusLog) {
ss= status instanceof MultiStatus ? ((MultiStatus) status).getChildren() : ss; IStatus[] ss= {status};
for (IStatus s : ss) { ss= status instanceof MultiStatus ? ((MultiStatus) status).getChildren() : ss;
msg.append("\t" + s.getMessage() + " "); for (IStatus s : ss) {
msg.append("\t" + s.getMessage() + " ");
Throwable t= s.getException();
cause= cause != null ? cause : t; Throwable t= s.getException();
if (t != null) { cause= cause != null ? cause : t;
msg.append(t.getMessage() != null ? t.getMessage() : t.getClass().getCanonicalName()); if (t != null) {
msg.append(t.getMessage() != null ? t.getMessage() : t.getClass().getCanonicalName());
}
msg.append("\n");
} }
msg.append("\n");
} }
} }
} }
@ -189,7 +191,7 @@ public class BaseTestCase extends TestCase {
corePlugin.getLog().removeLogListener(logListener); corePlugin.getLog().removeLogListener(logListener);
} }
} }
if (testThrowable != null) if (testThrowable != null)
throw testThrowable; throw testThrowable;
} }
@ -200,9 +202,9 @@ public class BaseTestCase extends TestCase {
super.run(result); super.run(result);
return; return;
} }
result.startTest(this); result.startTest(this);
TestResult r = new TestResult(); TestResult r = new TestResult();
super.run(r); super.run(r);
if (r.failureCount() == 1) { if (r.failureCount() == 1) {
@ -214,19 +216,19 @@ public class BaseTestCase extends TestCase {
} else if (r.errorCount() == 0 && r.failureCount() == 0) { } else if (r.errorCount() == 0 && r.failureCount() == 0) {
String err = "Unexpected success of " + getName(); String err = "Unexpected success of " + getName();
if (fBugNumber > 0) { if (fBugNumber > 0) {
err += ", bug #" + fBugNumber; err += ", bug #" + fBugNumber;
} }
result.addFailure(this, new AssertionFailedError(err)); result.addFailure(this, new AssertionFailedError(err));
} }
result.endTest(this); result.endTest(this);
} }
public void setExpectFailure(int bugNumber) { public void setExpectFailure(int bugNumber) {
fExpectFailure= true; fExpectFailure= true;
fBugNumber= bugNumber; fBugNumber= bugNumber;
} }
/** /**
* The last value passed to this method in the body of a testXXX method * The last value passed to this method in the body of a testXXX method
* will be used to determine whether or not the presence of non-OK status objects * will be used to determine whether or not the presence of non-OK status objects
@ -238,25 +240,25 @@ public class BaseTestCase extends TestCase {
public void setExpectedNumberOfLoggedNonOKStatusObjects(int count) { public void setExpectedNumberOfLoggedNonOKStatusObjects(int count) {
fExpectedLoggedNonOK= count; fExpectedLoggedNonOK= count;
} }
/** /**
* Some test steps need synchronizing against a CModel event. This class * Some test steps need synchronizing against a CModel event. This class
* is a very basic means of doing that. * is a very basic means of doing that.
*/ */
static protected class ModelJoiner implements IElementChangedListener { static protected class ModelJoiner implements IElementChangedListener {
private boolean[] changed= new boolean[1]; private boolean[] changed= new boolean[1];
public ModelJoiner() { public ModelJoiner() {
CoreModel.getDefault().addElementChangedListener(this); CoreModel.getDefault().addElementChangedListener(this);
} }
public void clear() { public void clear() {
synchronized (changed) { synchronized (changed) {
changed[0]= false; changed[0]= false;
changed.notifyAll(); changed.notifyAll();
} }
} }
public void join() throws CoreException { public void join() throws CoreException {
try { try {
synchronized(changed) { synchronized(changed) {
@ -268,24 +270,24 @@ public class BaseTestCase extends TestCase {
throw new CoreException(CCorePlugin.createStatus("Interrupted", e)); throw new CoreException(CCorePlugin.createStatus("Interrupted", e));
} }
} }
public void dispose() { public void dispose() {
CoreModel.getDefault().removeElementChangedListener(this); CoreModel.getDefault().removeElementChangedListener(this);
} }
@Override @Override
public void elementChanged(ElementChangedEvent event) { public void elementChanged(ElementChangedEvent event) {
// Only respond to post change events // Only respond to post change events
if (event.getType() != ElementChangedEvent.POST_CHANGE) if (event.getType() != ElementChangedEvent.POST_CHANGE)
return; return;
synchronized (changed) { synchronized (changed) {
changed[0]= true; changed[0]= true;
changed.notifyAll(); changed.notifyAll();
} }
} }
} }
public static void waitForIndexer(ICProject project) throws InterruptedException { public static void waitForIndexer(ICProject project) throws InterruptedException {
final PDOMManager indexManager = CCoreInternals.getPDOMManager(); final PDOMManager indexManager = CCoreInternals.getPDOMManager();
assertTrue(indexManager.joinIndexer(10000, npm())); assertTrue(indexManager.joinIndexer(10000, npm()));