Skip to content

Commit df49968

Browse files
author
Jörg Kubitz
committed
AbstractDocument fix concurrency (BadPositionCategoryException) #1067
By synchronized access to members used from different thread eclipse-jdt/eclipse.jdt.ui#1067
1 parent 690fac0 commit df49968

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

bundles/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/SynchronizableDocument.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void set(String text, long modificationStamp) {
202202
}
203203

204204
@Override
205-
public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
205+
synchronized public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
206206
Object lockObject= getLockObject();
207207
if (lockObject == null) {
208208
super.addPosition(category, position);
@@ -214,7 +214,7 @@ public void addPosition(String category, Position position) throws BadLocationEx
214214
}
215215

216216
@Override
217-
public void removePosition(String category, Position position) throws BadPositionCategoryException {
217+
synchronized public void removePosition(String category, Position position) throws BadPositionCategoryException {
218218
Object lockObject= getLockObject();
219219
if (lockObject == null) {
220220
super.removePosition(category, position);
@@ -226,7 +226,7 @@ public void removePosition(String category, Position position) throws BadPositio
226226
}
227227

228228
@Override
229-
public Position[] getPositions(String category) throws BadPositionCategoryException {
229+
synchronized public Position[] getPositions(String category) throws BadPositionCategoryException {
230230
Object lockObject= getLockObject();
231231
if (lockObject == null) {
232232
return super.getPositions(category);

bundles/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ protected void fireDocumentChanged(DocumentEvent event) {
773773
}
774774

775775
@Override
776-
protected void updateDocumentStructures(DocumentEvent event) {
776+
synchronized protected void updateDocumentStructures(DocumentEvent event) {
777777
super.updateDocumentStructures(event);
778778
ensureWellFormedSegmentation(computeAnchor(event));
779779
fMapping.projectionChanged();

bundles/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ static private class RegisteredReplace {
102102
private final ListenerList<IDocumentListener> fPrenotifiedDocumentListeners= new ListenerList<>(ListenerList.IDENTITY);
103103
/** The registered document partitioning listeners */
104104
private final ListenerList<IDocumentPartitioningListener> fDocumentPartitioningListeners= new ListenerList<>(ListenerList.IDENTITY);
105-
/** All positions managed by the document ordered by their start positions. */
105+
/** All positions managed by the document ordered by their start positions.
106+
* synchronized access */
106107
private final Map<String, List<Position>> fPositions= new HashMap<>();
107108
/**
108109
* All positions managed by the document ordered by their end positions.
109-
* @since 3.4
110+
* synchronized access
110111
*/
111112
private final Map<String, List<Position>> fEndPositions= new HashMap<>();
112113
/** All registered document position updaters */
@@ -242,15 +243,6 @@ protected List<IDocumentPartitioningListener> getDocumentPartitioningListeners()
242243
return asList(fDocumentPartitioningListeners);
243244
}
244245

245-
/**
246-
* Returns all positions managed by the document grouped by category.
247-
*
248-
* @return the document's positions
249-
*/
250-
protected Map<String, List<Position>> getDocumentManagedPositions() {
251-
return fPositions;
252-
}
253-
254246
@Override
255247
public IDocumentPartitioner getDocumentPartitioner() {
256248
return getDocumentPartitioner(DEFAULT_PARTITIONING);
@@ -335,7 +327,7 @@ public void removeDocumentPartitioningListener(IDocumentPartitioningListener lis
335327
}
336328

337329
@Override
338-
public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
330+
synchronized public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
339331

340332
if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength()))
341333
throw new BadLocationException();
@@ -345,12 +337,12 @@ public void addPosition(String category, Position position) throws BadLocationEx
345337

346338
List<Position> list= fPositions.get(category);
347339
if (list == null)
348-
throw new BadPositionCategoryException();
340+
throw new BadPositionCategoryException(category);
349341
list.add(computeIndexInPositionList(list, position.offset), position);
350342

351343
List<Position> endPositions= fEndPositions.get(category);
352344
if (endPositions == null)
353-
throw new BadPositionCategoryException();
345+
throw new BadPositionCategoryException(category);
354346
endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position);
355347
}
356348

@@ -363,7 +355,7 @@ public void addPosition(Position position) throws BadLocationException {
363355
}
364356

365357
@Override
366-
public void addPositionCategory(String category) {
358+
synchronized public void addPositionCategory(String category) {
367359

368360
if (category == null)
369361
return;
@@ -380,7 +372,7 @@ public void addPositionUpdater(IPositionUpdater updater) {
380372
}
381373

382374
@Override
383-
public boolean containsPosition(String category, int offset, int length) {
375+
synchronized public boolean containsPosition(String category, int offset, int length) {
384376

385377
if (category == null)
386378
return false;
@@ -408,7 +400,7 @@ public boolean containsPosition(String category, int offset, int length) {
408400
}
409401

410402
@Override
411-
public boolean containsPositionCategory(String category) {
403+
synchronized public boolean containsPositionCategory(String category) {
412404
if (category != null)
413405
return fPositions.containsKey(category);
414406
return false;
@@ -507,14 +499,14 @@ private int getOffset(boolean orderedByOffset, Position position) {
507499
}
508500

509501
@Override
510-
public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException {
502+
synchronized public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException {
511503

512504
if (0 > offset || offset > getLength())
513505
throw new BadLocationException();
514506

515507
List<Position> c= fPositions.get(category);
516508
if (c == null)
517-
throw new BadPositionCategoryException();
509+
throw new BadPositionCategoryException(category);
518510

519511
return computeIndexInPositionList(c, offset);
520512
}
@@ -647,7 +639,7 @@ protected void fireDocumentAboutToBeChanged(DocumentEvent event) {
647639
*
648640
* @param event the document event describing the change to which structures must be adapted
649641
*/
650-
protected void updateDocumentStructures(DocumentEvent event) {
642+
synchronized protected void updateDocumentStructures(DocumentEvent event) {
651643

652644
if (fDocumentPartitioners != null) {
653645
fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this);
@@ -918,22 +910,22 @@ public ITypedRegion[] computePartitioning(int offset, int length) throws BadLoca
918910
}
919911

920912
@Override
921-
public Position[] getPositions(String category) throws BadPositionCategoryException {
913+
synchronized public Position[] getPositions(String category) throws BadPositionCategoryException {
922914

923915
if (category == null)
924916
throw new BadPositionCategoryException();
925917

926918
List<Position> c= fPositions.get(category);
927919
if (c == null)
928-
throw new BadPositionCategoryException();
920+
throw new BadPositionCategoryException(category);
929921

930922
Position[] positions= new Position[c.size()];
931923
c.toArray(positions);
932924
return positions;
933925
}
934926

935927
@Override
936-
public String[] getPositionCategories() {
928+
synchronized public String[] getPositionCategories() {
937929
String[] categories= new String[fPositions.size()];
938930
Iterator<String> keys= fPositions.keySet().iterator();
939931
for (int i= 0; i < categories.length; i++)
@@ -970,7 +962,7 @@ public void insertPositionUpdater(IPositionUpdater updater, int index) {
970962
}
971963

972964
@Override
973-
public void removePosition(String category, Position position) throws BadPositionCategoryException {
965+
synchronized public void removePosition(String category, Position position) throws BadPositionCategoryException {
974966

975967
if (position == null)
976968
return;
@@ -980,12 +972,12 @@ public void removePosition(String category, Position position) throws BadPositio
980972

981973
List<Position> c= fPositions.get(category);
982974
if (c == null)
983-
throw new BadPositionCategoryException();
975+
throw new BadPositionCategoryException(category);
984976
removeFromPositionsList(c, position, true);
985977

986978
List<Position> endPositions= fEndPositions.get(category);
987979
if (endPositions == null)
988-
throw new BadPositionCategoryException();
980+
throw new BadPositionCategoryException(category);
989981
removeFromPositionsList(endPositions, position, false);
990982
}
991983

@@ -1037,13 +1029,13 @@ public void removePosition(Position position) {
10371029
}
10381030

10391031
@Override
1040-
public void removePositionCategory(String category) throws BadPositionCategoryException {
1032+
synchronized public void removePositionCategory(String category) throws BadPositionCategoryException {
10411033

10421034
if (category == null)
10431035
return;
10441036

10451037
if ( !containsPositionCategory(category))
1046-
throw new BadPositionCategoryException();
1038+
throw new BadPositionCategoryException(category);
10471039

10481040
fPositions.remove(category);
10491041
fEndPositions.remove(category);
@@ -1649,10 +1641,10 @@ private boolean isWithinRegion(Position region, Position position, boolean canSt
16491641
* @throws BadPositionCategoryException if category is undefined in this document
16501642
* @since 3.4
16511643
*/
1652-
private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException {
1644+
synchronized private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException {
16531645
List<Position> positions= fPositions.get(category);
16541646
if (positions == null)
1655-
throw new BadPositionCategoryException();
1647+
throw new BadPositionCategoryException(category);
16561648

16571649
int indexStart= computeIndexInPositionList(positions, offset, true);
16581650
int indexEnd= computeIndexInPositionList(positions, offset + length, true);
@@ -1671,10 +1663,10 @@ private List<Position> getStartingPositions(String category, int offset, int len
16711663
* @throws BadPositionCategoryException if category is undefined in this document
16721664
* @since 3.4
16731665
*/
1674-
private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException {
1666+
synchronized private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException {
16751667
List<Position> positions= fEndPositions.get(category);
16761668
if (positions == null)
1677-
throw new BadPositionCategoryException();
1669+
throw new BadPositionCategoryException(category);
16781670

16791671
int indexStart= computeIndexInPositionList(positions, offset, false);
16801672
int indexEnd= computeIndexInPositionList(positions, offset + length, false);

0 commit comments

Comments
 (0)