diff --git a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java index 3533ad07c22..b62bae32287 100644 --- a/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java +++ b/bundles/org.eclipse.ui.editors/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLine.java @@ -53,6 +53,12 @@ public String getText() { @Override public StyleRange[] getStyleRanges() { StyledText textWidget= sourceViewer.getTextWidget(); + int widgetLineNumber = getWidgetLineNumber(); + + if (widgetLineNumber > textWidget.getLineCount()) { + return null; + } + int offsetAtLine= textWidget.getOffsetAtLine(getWidgetLineNumber()); StyleRange[] styleRanges= textWidget.getStyleRanges(offsetAtLine, getText().length()); for (StyleRange styleRange : styleRanges) { diff --git a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java index 99ee26000f0..5c34d24f0db 100644 --- a/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java +++ b/tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyLineTest.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.texteditor.stickyscroll; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.junit.After; import org.junit.Before; @@ -94,6 +95,16 @@ public void testGetStyleRanges() { assertEquals(2, styleRanges[1].length); } + @Test + public void testGetStyleRangesIgnoresOutOfBoundLines() { + textWidget.setText("line1\nline2\nline3"); + + StickyLine stickyLineOutOfBound = new StickyLine(10, sourceViewer); + StyleRange[] styleRanges = stickyLineOutOfBound.getStyleRanges(); + + assertNull(styleRanges); + } + @Test public void WithSourceViewerLineMapping() { sourceViewer = new SourceViewerWithLineMapping(shell, null, SWT.None);