diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java index 31cd0c48b0d..128f9ea5924 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java @@ -231,6 +231,10 @@ public class CodeInsightUtils { Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document == null) return null; + if (line >= document.getLineCount()) { + return null; + } + int lineStartOffset = document.getLineStartOffset(line); return CharArrayUtil.shiftForward(document.getCharsSequence(), lineStartOffset, " \t"); } @@ -240,6 +244,10 @@ public class CodeInsightUtils { Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document == null) return null; + if (line >= document.getLineCount()) { + return null; + } + int lineStartOffset = document.getLineEndOffset(line); return CharArrayUtil.shiftBackward(document.getCharsSequence(), lineStartOffset, " \t"); }