Skip to content

Commit 83ec4c1

Browse files
author
rcartwright
committed
This revision includes some minor bug fixes including a concurrency
bug in ReaderWriterLockTest and a index-out-bounds-bug in ConcreteRegionManager. The following files were modified: M src/edu/rice/cs/util/ReaderWriterLockTest.java M src/edu/rice/cs/drjava/model/ConcreteRegionManager.java M src/edu/rice/cs/drjava/ui/RegionsListPanel.java M src/edu/rice/cs/drjava/ui/FindResultsPanel.java M src/edu/rice/cs/drjava/ui/BreakpointsPanel.java M src/edu/rice/cs/drjava/ui/RegionsTreePanel.java git-svn-id: file:///tmp/test-svn/trunk@5680 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent fe83132 commit 83ec4c1

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public R getRegionAt(OpenDefinitionsDocument odd, int offset) {
138138

139139
/** Finds the interval of regions in odd such that the line label (excerpt) for the region contains offset. */
140140
public Pair<R, R> getRegionInterval(OpenDefinitionsDocument odd, int offset) {
141-
/* */ assert Utilities.TEST_MODE || EventQueue.isDispatchThread();
141+
assert Utilities.TEST_MODE || EventQueue.isDispatchThread();
142142

143143
// System.err.println("getRegionsNear(" + odd + ", " + offset + ") called");
144144

@@ -147,8 +147,9 @@ public Pair<R, R> getRegionInterval(OpenDefinitionsDocument odd, int offset) {
147147
* Since empty regions are ignore (and deleted as soon as they are found), the end of a containing region must be
148148
* less than 120 characters from offset. Find the tail set of all regions [start, end) where offset - 120 < end.
149149
*/
150-
@SuppressWarnings("unchecked")
151-
SortedSet<R> tail = getTailSet((R) new DocumentRegion(odd, 0, offset - 119));
150+
@SuppressWarnings("unchecked") // max operator inserted to ensure that [start,end) interval is non-degenerate.
151+
SortedSet<R> tail = getTailSet((R) new DocumentRegion(odd, 0, Math.max(0, offset - 119)));
152+
152153

153154
/* Search tail, selecting first and last regions r such that r.getLineEnd() >= offset and r.getLineStart <= offset.
154155
* The tail is totally order on BOTH getLineStart() and getLineEnd() because the functions mapping start to lineStart

drjava/src/edu/rice/cs/drjava/ui/BreakpointsPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void regionChanged(final Breakpoint bp) {
9494
*/
9595
public void regionRemoved(final Breakpoint bp) { removeRegion(bp); }
9696
});
97-
_debugger = _model.getDebugger();
97+
_debugger = getGlobalModel().getDebugger();
9898
}
9999

100100
/** Action performed when the Enter key is pressed. Should be overridden. */

drjava/src/edu/rice/cs/drjava/ui/FindResultsPanel.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@ public class FindResultsPanel extends RegionsTreePanel<MovingDocumentRegion> {
6767

6868
// The following field has been hoisted into RegionsTreePanel
6969
// protected final RegionManager<MovingDocumentRegion> _regionManager;
70-
protected final String _searchString;
71-
protected final boolean _searchAll;
72-
protected final boolean _searchSelectionOnly;
73-
protected final boolean _matchCase;
74-
protected final boolean _wholeWord;
75-
protected final boolean _noComments;
76-
protected final boolean _noTestCases;
77-
protected final WeakReference<OpenDefinitionsDocument> _doc;
78-
protected final FindReplacePanel _findReplace;
79-
protected final MovingDocumentRegion _region; //document region used for search limited selection function
70+
private final String _searchString;
71+
private final boolean _searchAll;
72+
private final boolean _searchSelectionOnly;
73+
private final boolean _matchCase;
74+
private final boolean _wholeWord;
75+
private final boolean _noComments;
76+
private final boolean _noTestCases;
77+
private final WeakReference<OpenDefinitionsDocument> _doc;
78+
private final FindReplacePanel _findReplace;
79+
private final MovingDocumentRegion _region; //document region used for search limited selection function
8080

81-
protected JButton _findAgainButton;
82-
protected JButton _goToButton;
83-
protected JButton _bookmarkButton;
84-
protected JButton _removeButton;
85-
protected JComboBox<Color> _colorBox;
86-
protected int _lastIndex;
81+
private volatile JButton _findAgainButton;
82+
private volatile JButton _goToButton;
83+
private volatile JButton _bookmarkButton;
84+
private volatile JButton _removeButton;
85+
private volatile JComboBox<Color> _colorBox;
86+
private volatile int _lastIndex;
8787

8888
/** Saved option listeners kept in this field so they can be removed for garbage collection */
89-
private LinkedList<Pair<Option<Color>, OptionListener<Color>>> _colorOptionListeners =
89+
private final LinkedList<Pair<Option<Color>, OptionListener<Color>>> _colorOptionListeners =
9090
new LinkedList<Pair<Option<Color>, OptionListener<Color>>>();
9191

9292
/** Constructs a new find results panel. This is swing class which should only be accessed from the event thread.
@@ -152,8 +152,8 @@ public void regionChanged(MovingDocumentRegion r) {
152152
}
153153

154154
class ColorComboRenderer extends JPanel implements ListCellRenderer<Color> {
155-
private Color _color = DrJava.getConfig().getSetting(OptionConstants.FIND_RESULTS_COLORS[_colorBox.getSelectedIndex()]);
156-
private DefaultListCellRenderer _defaultRenderer = new DefaultListCellRenderer();
155+
private volatile Color _color = DrJava.getConfig().getSetting(OptionConstants.FIND_RESULTS_COLORS[_colorBox.getSelectedIndex()]);
156+
private final DefaultListCellRenderer _defaultRenderer = new DefaultListCellRenderer();
157157
private final Dimension _size = new Dimension(0, 20);
158158
private final CompoundBorder _compoundBorder =
159159
new CompoundBorder(new MatteBorder(2, 10, 2, 10, Color.white), new LineBorder(Color.black));

drjava/src/edu/rice/cs/drjava/ui/RegionsListPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
* @version $Id$
6060
*/
6161
public abstract class RegionsListPanel<R extends IDocumentRegion> extends TabbedPanel {
62-
protected volatile JPanel _leftPane;
62+
private volatile JPanel _leftPane;
6363

64-
protected volatile JList<RegionListUserObj<R>> _list;
65-
protected volatile DefaultListModel<RegionListUserObj<R>> _listModel;
66-
protected String _title;
64+
private volatile JList<RegionListUserObj<R>> _list;
65+
private volatile DefaultListModel<RegionListUserObj<R>> _listModel;
66+
protected volatile String _title;
6767

6868
protected final SingleDisplayModel _model;
6969
protected final MainFrame _frame;

drjava/src/edu/rice/cs/drjava/ui/RegionsTreePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public abstract class RegionsTreePanel<R extends OrderedDocumentRegion> extends
7575

7676
private volatile String _title;
7777
private volatile RegionManager<R> _regionManager;
78-
protected volatile JPopupMenu _regionPopupMenu;
79-
protected final SingleDisplayModel _model;
78+
private volatile JPopupMenu _regionPopupMenu;
79+
private final SingleDisplayModel _model;
8080
protected final MainFrame _frame;
8181
protected volatile JPanel _buttonPanel;
8282

drjava/src/edu/rice/cs/util/ReaderWriterLockTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void _notify() {
7676
/** Tests that multiple readers can run without causing deadlock. We can't really impose any ordering on their output.
7777
*/
7878
public void testMultipleReaders() throws InterruptedException {
79-
final StringBuilder buf = new StringBuilder();
79+
final StringBuffer buf = new StringBuffer(); // StringBuffer is designed for concurrent access
8080

8181
// Create three threads
8282
ReaderThread r1 = new PrinterReaderThread("r1 ", buf);
@@ -102,7 +102,7 @@ public void testMultipleReaders() throws InterruptedException {
102102

103103
/** Tests that multiple writers run in mutually exclusive intervals without causing deadlock. */
104104
public void testMultipleWriters() throws InterruptedException {
105-
final StringBuilder buf = new StringBuilder();
105+
final StringBuffer buf = new StringBuffer(); // StringBuffer is designed for concurrent access
106106

107107
// Create three threads
108108
WriterThread w1 = new PrinterWriterThread("w1 ", buf);
@@ -226,7 +226,7 @@ public void testCannotReadInAWrite() {
226226
* enforce that no one interferes with output from a writer.
227227
*/
228228
public void testMultipleReadersAndWriters() throws InterruptedException {
229-
final StringBuilder buf = new StringBuilder();
229+
final StringBuffer buf = new StringBuffer(); // StringBuffer is designed for concurrent access
230230

231231
// Create threads
232232
WriterThread w1 = new PrinterWriterThread("w1 ", buf);
@@ -298,14 +298,14 @@ public void run() {
298298
/** A ReaderThread which repeatedly prints to a buffer. */
299299
public class PrinterReaderThread extends ReaderThread {
300300
PrintCommand _command;
301-
public PrinterReaderThread(String msg, final StringBuilder buf) { _command = new PrintCommand(msg, buf); }
301+
public PrinterReaderThread(String msg, final StringBuffer buf) { _command = new PrintCommand(msg, buf); }
302302
public void read() { _command.print(); }
303303
}
304304

305305
/** A WriterThread which repeatedly prints to a buffer. */
306306
public class PrinterWriterThread extends WriterThread {
307307
PrintCommand _command;
308-
public PrinterWriterThread(String msg, final StringBuilder buf) { _command = new PrintCommand(msg, buf); }
308+
public PrinterWriterThread(String msg, final StringBuffer buf) { _command = new PrintCommand(msg, buf); }
309309
public void write() { _command.print(); }
310310
}
311311

@@ -316,11 +316,11 @@ public class PrintCommand {
316316
/** Number of milliseconds to wait between iterations */
317317
volatile int _waitMillis = 5;
318318
/** Buffer to print to */
319-
final StringBuilder _buf;
319+
final StringBuffer _buf; // StringBuffer is designed for concurrent access
320320
/** Message to print */
321321
final String _msg;
322322
/** Creates a new command to print to a buffer during a read or write. */
323-
public PrintCommand(String msg, StringBuilder buf) {
323+
public PrintCommand(String msg, StringBuffer buf) {
324324
_msg = msg;
325325
_buf = buf;
326326
}

0 commit comments

Comments
 (0)