From 554fd8b1c6eea974181c0246bb555fbe524c6817 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Thu, 22 Jan 2015 16:28:37 +0300 Subject: [PATCH] Skip line offset on out of range line numbers --- .../kotlin/idea/codeInsight/CodeInsightUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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"); }