Fix AIOOBE when completion started on empty file
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Fri, 13 Apr 2018 11:20:22 +0000 (14:20 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Fri, 13 Apr 2018 11:20:22 +0000 (14:20 +0300)
plugins/stats-collector/src/com/intellij/stats/ngram/NGram.kt

index f5c722be6a2f99812800ee2af7d53c37f33d549e..c06daa093707a09f2e169e5dafc3426a8ae095ee 100644 (file)
@@ -49,7 +49,7 @@ data class NGram(val elements: List<String>) {
         fun getNGramForElement(element: PsiElement) : NGram {
             val elements = TreeTraversal.getElements(element.containingFile ?: return NGram.INVALID)
             val index = elements.indexOf(element.parent.node)
         fun getNGramForElement(element: PsiElement) : NGram {
             val elements = TreeTraversal.getElements(element.containingFile ?: return NGram.INVALID)
             val index = elements.indexOf(element.parent.node)
-            if (index == -1) {
+            if (index == -1 || index < NGram.N) {
                 return NGram.INVALID
             }
             val nGramElements = ArrayList<String>()
                 return NGram.INVALID
             }
             val nGramElements = ArrayList<String>()