Skip to content

Commit 2321a9b

Browse files
committed
Fix array index out of bounds in getAgentCaller method
The getAgentCaller method in Analyzer.java had a bug where it could access frames.get(i + 1) when i = frames.size() - 1, causing an IndexOutOfBoundsException. Fixed by: - Changing loop condition from i >= 0 to i >= 1 - Changing access from frames.get(i + 1) to frames.get(i - 1) This ensures we never access beyond array bounds while maintaining the correct logic to find the caller of agent methods.
1 parent f87d454 commit 2321a9b

File tree

1 file changed

+2
-2
lines changed
  • benchmark-jfr-analyzer/src/main/java/io/opentelemetry/javaagent/benchmark/jfr

1 file changed

+2
-2
lines changed

benchmark-jfr-analyzer/src/main/java/io/opentelemetry/javaagent/benchmark/jfr/Analyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ private static Set<String> getAgentCallers(List<RecordedEvent> events) {
6565
@Nullable
6666
private static String getAgentCaller(RecordedStackTrace stackTrace) {
6767
List<RecordedFrame> frames = stackTrace.getFrames();
68-
for (int i = frames.size() - 1; i >= 0; i--) {
68+
for (int i = frames.size() - 1; i >= 1; i--) {
6969
RecordedFrame frame = frames.get(i);
7070
RecordedMethod method = frame.getMethod();
7171
if (isAgentMethod(method)) {
72-
RecordedFrame callerFrame = frames.get(i + 1);
72+
RecordedFrame callerFrame = frames.get(i - 1);
7373
RecordedMethod callerMethod = callerFrame.getMethod();
7474
return getStackTraceElement(callerMethod, callerFrame);
7575
}

0 commit comments

Comments
 (0)