Skip to content

Commit d390a10

Browse files
committed
Add null checks for position in ProjectionViewer to prevent NPEs
Fixes #4078
1 parent 0d1c75b commit d390a10

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ private void expandProjectionAnnotationsBorderingRegion(Region region) throws Ba
793793
for (Iterator<Annotation> it= fProjectionAnnotationModel.getAnnotationIterator(); it.hasNext();) {
794794
Annotation annotation= it.next();
795795
Position position= fProjectionAnnotationModel.getPosition(annotation);
796-
if (bordersOrSurroundsRegion(position, region)) {
796+
if (position != null && bordersOrSurroundsRegion(position, region)) {
797797
fProjectionAnnotationModel.expand(annotation);
798798
}
799799
}
@@ -808,7 +808,7 @@ private void hideProjectionAnnotationsOutsideOfVisibleRegion() throws BadLocatio
808808

809809
private void hideProjectionAnnotationIfPartsAreOutsideOfVisibleRegion(Annotation annotation) throws BadLocationException {
810810
Position position= fProjectionAnnotationModel.getPosition(annotation);
811-
if (annotation instanceof ProjectionAnnotation a) {
811+
if (annotation instanceof ProjectionAnnotation a && position != null) {
812812
if (overlapsWithNonVisibleRegions(position.getOffset(), position.getLength())) {
813813
a.setHidden(true);
814814
} else {
@@ -1355,6 +1355,9 @@ public IRegion computeCollapsedRegion(Position position) {
13551355
* @since 3.1
13561356
*/
13571357
IRegion[] computeCollapsedRegions(Position position) {
1358+
if (position == null) {
1359+
return null;
1360+
}
13581361
try {
13591362
IDocument document= getDocument();
13601363
if (document == null) {

0 commit comments

Comments
 (0)