Skip to content

Commit 3c8d894

Browse files
author
rcartwright
committed
This revision corrects some thread interference (synchronization
protocol) errors in DefaultJUnitErrorModel and assorted small stylistic and formatting issues in other files. The following files were modified: M src/edu/rice/cs/drjava/DrJava.java M src/edu/rice/cs/drjava/model/debug/jpda/JPDADebugger.java M src/edu/rice/cs/drjava/model/GlobalModelTestCase.java M src/edu/rice/cs/drjava/model/cache/DocumentCache.java M src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java M src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java M src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java M src/edu/rice/cs/drjava/RemoteControlClient.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/drjava/ui/TabbedPanel.java M src/edu/rice/cs/drjava/ui/AbstractDJPane.java M src/edu/rice/cs/drjava/ui/ReverseHighlighter.java M src/edu/rice/cs/util/text/SwingDocument.java M src/edu/rice/cs/util/docnavigation/JListSortNavigator.java M src/edu/rice/cs/util/docnavigation/JTreeSortNavigator.java M src/edu/rice/cs/util/swing/ScrollableListSelectionDialog.java M src/edu/rice/cs/util/JoinInputStream.java M src/edu/rice/cs/util/InputStreamRedirector.java M src/edu/rice/cs/util/newjvm/IntegratedMasterSlaveTest.java git-svn-id: file:///tmp/test-svn/trunk@5443 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 8cb3141 commit 3c8d894

19 files changed

+361
-359
lines changed

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class DrJava {
159159

160160
/** Returns the configuration object with all customized and default values. */
161161
public static synchronized FileConfiguration getConfig() {
162-
if (_config==null) {
162+
if (_config == null) {
163163
_config = _initConfig(); // read specified .djrava file into _config
164164
}
165165
return _config;
@@ -201,9 +201,9 @@ public static synchronized void clearFilesToOpen() {
201201
* @return true if successful
202202
*/
203203
public static synchronized boolean openWithRemoteControl(ArrayList<String> files, int numAttempts) {
204-
if (!DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED) ||
205-
!_restartedDrJavaUsesRemoteControl ||
206-
(files.size()==0)) return false;
204+
if (! DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_ENABLED) ||
205+
! _restartedDrJavaUsesRemoteControl ||
206+
files.size() == 0) return false;
207207

208208
ArrayList<String> fs = new ArrayList<String>(files);
209209
int failCount = 0;
@@ -227,9 +227,7 @@ public static synchronized boolean openWithRemoteControl(ArrayList<String> files
227227
catch(InterruptedException ie) { /* just try again now */ }
228228
}
229229
}
230-
catch(IOException ioe) {
231-
ioe.printStackTrace();
232-
}
230+
catch(IOException ioe) { ioe.printStackTrace(); }
233231
}
234232
return false; // failure
235233
}

drjava/src/edu/rice/cs/drjava/RemoteControlClient.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,26 @@ public class RemoteControlClient {
4848
*/
4949
protected static Boolean _serverRunning = null;
5050

51-
/** Contains the name of the user running the server, or is null if no server is running.
52-
*/
51+
/** Contains the name of the user running the server, or is null if no server is running. */
5352
protected static String _serverUser = null;
5453

55-
/** Time in ms until the client decides the server is not running.
56-
*/
54+
/** Time in ms until the client decides the server is not running. */
5755
public static final int REMOTE_CONTROL_TIMEOUT = 250;
5856

5957
/** Return true if a DrJava remote control server is running.
60-
* @return true if running
61-
*/
58+
* @return true if running
59+
*/
6260
public static synchronized boolean isServerRunning() {
6361
if (_serverRunning == null) {
64-
try {
65-
openFile(null);
66-
}
62+
try { openFile(null); }
6763
catch(IOException e) { _serverRunning = false; }
6864
}
6965
return _serverRunning;
7066
}
7167

7268
/** Return the name of the user running the server, or null if no server is running.
73-
* @return user name or null
74-
*/
69+
* @return user name or null
70+
*/
7571
public static String getServerUser() { return _serverUser; }
7672

7773
/** Tell the existing DrJava instance to open a file.

drjava/src/edu/rice/cs/drjava/model/GlobalModelTestCase.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ public void waitJUnitDone() throws InterruptedException {
12161216
synchronized(_junitLock) { while (! _junitDone) { _junitLock.wait(); } }
12171217
}
12181218

1219-
private void _notifyJUnitDone() {
1219+
protected void _notifyJUnitDone() { // access in subclass JUnitNonTestListener
12201220
synchronized(_junitLock) {
12211221
_junitDone = true;
12221222
_junitLock.notifyAll();
@@ -1270,7 +1270,7 @@ public synchronized void resetJUnitCounts() {
12701270
_notifyJUnitDone();
12711271
}
12721272
@Override public void junitEnded() {
1273-
//assertJUnitSuiteStartedCount(1);
1273+
// assertJUnitSuiteStartedCount(1);
12741274
if (printMessages) System.out.println("junitEnded event!");
12751275
synchronized(this) { junitEndCount++; }
12761276
_log.log("junitEnded() called; notifying JUnitDone");
@@ -1287,11 +1287,7 @@ public void nonTestCase(boolean isTestAll, boolean didCompileFail) {
12871287
synchronized(this) { nonTestCaseCount++; }
12881288
assertEquals("Non test case heard the wrong value for test current/test all", _shouldBeTestAll, isTestAll);
12891289
// Utilities.show("synchronizing on _junitLock");
1290-
synchronized(_junitLock) {
1291-
// System.err.println("JUnit aborted as nonTestCase");
1292-
_junitDone = true;
1293-
_junitLock.notify();
1294-
}
1290+
_notifyJUnitDone();
12951291
}
12961292
}
12971293

drjava/src/edu/rice/cs/drjava/model/cache/DocumentCache.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ private DefinitionsDocument makeDocument() {
176176
_doc = _rec.make();
177177
assert _doc != null;
178178
// update documents if necessary
179-
if (_keywords!=null) {
179+
if (_keywords != null) {
180180
_doc.setKeywords(_keywords); _keywords.clear(); _keywords = null;
181181
}
182182
}
183-
catch(Exception e) { throw new UnexpectedException(e); }
183+
catch(IOException e) { throw new UnexpectedException(e); }
184+
catch(BadLocationException e) { throw new UnexpectedException(e); }
184185
// Utilities.showDebug("Document " + _doc + " reconstructed; _stat = " + _stat);
185186
// System.err.println("Making document for " + this);
186187
if (_stat == NOT_IN_QUEUE) add(); // add this to queue
@@ -321,13 +322,15 @@ private void kickOut(boolean isClosing) {
321322
/** Set the specified keywords as keywords for syntax highlighting.
322323
* @param keywords keywords to highlight */
323324
public void setKeywords(Set<String> keywords) {
324-
if (_doc != null) {
325-
// resident
326-
_doc.setKeywords(keywords);
327-
}
328-
else {
329-
// virtualized
330-
_keywords = new HashSet<String>(keywords);
325+
synchronized(_cacheLock) {
326+
if (_doc != null) {
327+
// resident
328+
_doc.setKeywords(keywords);
329+
}
330+
else {
331+
// virtualized
332+
_keywords = new HashSet<String>(keywords);
333+
}
331334
}
332335
}
333336
}

drjava/src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ private void _compileFiles(List<File> files, File buildDir) throws IOException {
345345
if (errors.isEmpty()) {
346346
CompilerInterface compiler = getActiveCompiler();
347347

348+
// Mutual exclusion with JUnit code that finds all test classes (in DefaultJUnitModel)
348349
synchronized(_compilerLock) {
349350
if (preprocessedFiles == null) {
350351
errors.addAll(compiler.compile(files, classPath, null, buildDir, bootClassPath, null, true));

drjava/src/edu/rice/cs/drjava/model/debug/jpda/JPDADebugger.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,11 +1933,13 @@ public ThreadReference remove(long id) throws NoSuchElementException {
19331933
throw new NoSuchElementException("Thread " + id + " not found in debugger suspended threads stack!");
19341934
}
19351935

1936-
public synchronized boolean contains(long id) {
1937-
for (int i = 0; i < size(); i++) {
1938-
if (get(i).uniqueID() == id) return true;
1936+
public boolean contains(long id) {
1937+
synchronized(this) {
1938+
for (int i = 0; i < size(); i++) {
1939+
if (get(i).uniqueID() == id) return true;
1940+
}
1941+
return false;
19391942
}
1940-
return false;
19411943
}
19421944

19431945
public boolean isEmpty() { return empty(); }

0 commit comments

Comments
 (0)