diff --git a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java index 6a415d0eb1ee..e13e33410874 100644 --- a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java +++ b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.rt.debugger.agent; import java.lang.ref.ReferenceQueue; @@ -250,12 +250,19 @@ public class CaptureStorage { List stackTrace = stack.getStackTrace(); if (stack instanceof DeepCapturedStack) { int depth = 0; - for (; depth < stackTrace.size(); depth++) { + int size = stackTrace.size(); + for (; depth < size; depth++) { if (stackTrace.get(depth).getMethodName().endsWith(GENERATED_INSERT_METHOD_POSTFIX)) { break; } } - stackTrace = stackTrace.subList(0, depth + 2); + int newEnd = depth + 2; + if (newEnd > size) { + IllegalStateException exception = new IllegalStateException("Insertion point was not found in stack:"); + exception.setStackTrace(stackTrace.toArray(new StackTraceElement[0])); + throw exception; + } + stackTrace = stackTrace.subList(0, newEnd); stack = ((DeepCapturedStack)stack).myInsertMatch; } else {