From 45a8e6d446d4d07da2376ded2ace318895d2d424 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Thu, 21 Nov 2019 12:38:59 +0300 Subject: [PATCH] IDEA-223505 Critical Error in IDEA Async Stacktraces (IndexOutOfBOundsException) - more logging GitOrigin-RevId: f846d48e944013da203adaefeb90b7bb7149afcf --- .../intellij/rt/debugger/agent/CaptureStorage.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 {