Skip to content

Commit 65f4b90

Browse files
Jörg Kubitzjukzi
authored andcommitted
SynchronizableDocument: fix (BadPositionCategoryException)
Adds missing synchronized overrides of underlying AbstractDocument To synchronize all accesses to AbstractDocument.fEndPositions especially by addPositionCategory() eclipse-jdt/eclipse.jdt.ui#1067
1 parent e3382fc commit 65f4b90

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.internal.filebuffers;
1515

16+
import java.util.List;
17+
import java.util.Map;
18+
1619
import org.eclipse.jface.text.BadLocationException;
1720
import org.eclipse.jface.text.BadPartitioningException;
1821
import org.eclipse.jface.text.BadPositionCategoryException;
1922
import org.eclipse.jface.text.Document;
23+
import org.eclipse.jface.text.DocumentEvent;
2024
import org.eclipse.jface.text.DocumentRewriteSession;
2125
import org.eclipse.jface.text.DocumentRewriteSessionType;
2226
import org.eclipse.jface.text.IDocumentExtension4;
@@ -38,6 +42,97 @@ public class SynchronizableDocument extends Document implements ISynchronizable
3842

3943
private Object fLockObject;
4044

45+
@Override
46+
protected void updateDocumentStructures(DocumentEvent event) {
47+
Object lockObject= getLockObject();
48+
if (lockObject == null) {
49+
super.updateDocumentStructures(event);
50+
return;
51+
}
52+
synchronized (lockObject) {
53+
super.updateDocumentStructures(event);
54+
}
55+
}
56+
57+
@Override
58+
public void removePositionCategory(String category) throws BadPositionCategoryException {
59+
Object lockObject= getLockObject();
60+
if (lockObject == null) {
61+
super.removePositionCategory(category);
62+
return;
63+
}
64+
synchronized (lockObject) {
65+
super.removePositionCategory(category);
66+
}
67+
}
68+
69+
@Override
70+
public String[] getPositionCategories() {
71+
Object lockObject= getLockObject();
72+
if (lockObject == null) {
73+
return super.getPositionCategories();
74+
}
75+
synchronized (lockObject) {
76+
return super.getPositionCategories();
77+
}
78+
}
79+
80+
@Override
81+
protected Map<String, List<Position>> getDocumentManagedPositions() {
82+
Object lockObject= getLockObject();
83+
if (lockObject == null) {
84+
return super.getDocumentManagedPositions();
85+
}
86+
synchronized (lockObject) {
87+
return super.getDocumentManagedPositions();
88+
}
89+
}
90+
91+
@Override
92+
public boolean containsPositionCategory(String category) {
93+
Object lockObject= getLockObject();
94+
if (lockObject == null) {
95+
return super.containsPositionCategory(category);
96+
}
97+
synchronized (lockObject) {
98+
return super.containsPositionCategory(category);
99+
}
100+
}
101+
102+
@Override
103+
public boolean containsPosition(String category, int offset, int length) {
104+
Object lockObject= getLockObject();
105+
if (lockObject == null) {
106+
return super.containsPosition(category, offset, length);
107+
}
108+
synchronized (lockObject) {
109+
return super.containsPosition(category, offset, length);
110+
}
111+
}
112+
113+
@Override
114+
public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException {
115+
Object lockObject= getLockObject();
116+
if (lockObject == null) {
117+
return super.computeIndexInCategory(category, offset);
118+
}
119+
synchronized (lockObject) {
120+
return super.computeIndexInCategory(category, offset);
121+
}
122+
}
123+
124+
@Override
125+
public void addPositionCategory(String category) {
126+
Object lockObject= getLockObject();
127+
if (lockObject == null) {
128+
super.addPositionCategory(category);
129+
return;
130+
}
131+
synchronized (lockObject) {
132+
super.addPositionCategory(category);
133+
}
134+
}
135+
41136
@Override
42137
public synchronized void setLockObject(Object lockObject) {
43138
fLockObject= lockObject;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,12 @@ public void addPosition(String category, Position position) throws BadLocationEx
345345

346346
List<Position> list= fPositions.get(category);
347347
if (list == null)
348-
throw new BadPositionCategoryException();
348+
throw new BadPositionCategoryException(category);
349349
list.add(computeIndexInPositionList(list, position.offset), position);
350350

351351
List<Position> endPositions= fEndPositions.get(category);
352352
if (endPositions == null)
353-
throw new BadPositionCategoryException();
353+
throw new BadPositionCategoryException(category);
354354
endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position);
355355
}
356356

@@ -514,7 +514,7 @@ public int computeIndexInCategory(String category, int offset) throws BadLocatio
514514

515515
List<Position> c= fPositions.get(category);
516516
if (c == null)
517-
throw new BadPositionCategoryException();
517+
throw new BadPositionCategoryException(category);
518518

519519
return computeIndexInPositionList(c, offset);
520520
}
@@ -925,7 +925,7 @@ public Position[] getPositions(String category) throws BadPositionCategoryExcept
925925

926926
List<Position> c= fPositions.get(category);
927927
if (c == null)
928-
throw new BadPositionCategoryException();
928+
throw new BadPositionCategoryException(category);
929929

930930
Position[] positions= new Position[c.size()];
931931
c.toArray(positions);
@@ -980,12 +980,12 @@ public void removePosition(String category, Position position) throws BadPositio
980980

981981
List<Position> c= fPositions.get(category);
982982
if (c == null)
983-
throw new BadPositionCategoryException();
983+
throw new BadPositionCategoryException(category);
984984
removeFromPositionsList(c, position, true);
985985

986986
List<Position> endPositions= fEndPositions.get(category);
987987
if (endPositions == null)
988-
throw new BadPositionCategoryException();
988+
throw new BadPositionCategoryException(category);
989989
removeFromPositionsList(endPositions, position, false);
990990
}
991991

@@ -1043,7 +1043,7 @@ public void removePositionCategory(String category) throws BadPositionCategoryEx
10431043
return;
10441044

10451045
if ( !containsPositionCategory(category))
1046-
throw new BadPositionCategoryException();
1046+
throw new BadPositionCategoryException(category);
10471047

10481048
fPositions.remove(category);
10491049
fEndPositions.remove(category);
@@ -1674,7 +1674,7 @@ private List<Position> getStartingPositions(String category, int offset, int len
16741674
private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException {
16751675
List<Position> positions= fEndPositions.get(category);
16761676
if (positions == null)
1677-
throw new BadPositionCategoryException();
1677+
throw new BadPositionCategoryException(category);
16781678

16791679
int indexStart= computeIndexInPositionList(positions, offset, false);
16801680
int indexEnd= computeIndexInPositionList(positions, offset + length, false);

0 commit comments

Comments
 (0)