Skip to content

Avoid NegativeArraySizeException in ProxyLeakTask on short stack traces#2406

Open
vasiliy-mikhailov wants to merge 1 commit into
brettwooldridge:devfrom
vasiliy-mikhailov:fix/proxyleaktask-short-stacktrace
Open

Avoid NegativeArraySizeException in ProxyLeakTask on short stack traces#2406
vasiliy-mikhailov wants to merge 1 commit into
brettwooldridge:devfrom
vasiliy-mikhailov:fix/proxyleaktask-short-stacktrace

Conversation

@vasiliy-mikhailov

Copy link
Copy Markdown

ProxyLeakTask.run() trims the first 5 (HikariCP-internal) frames from the captured stack trace:

final var trace = new StackTraceElement[stackTrace.length - 5];
System.arraycopy(stackTrace, 5, trace, 0, trace.length);

When the leak-detection exception has fewer than 5 frames (for example when stack traces are disabled via -XX:-StackTraceInThrowable, or in minimal stacks), stackTrace.length - 5 is negative and the scheduled leak-detection task throws NegativeArraySizeException instead of logging the leak warning.

This clamps the trimmed length to zero (and skips the copy when empty). Includes a regression test.

ProxyLeakTask.run() trims the first 5 (HikariCP-internal) frames from the
captured stack trace via new StackTraceElement[stackTrace.length - 5]. When the
leak-detection exception has fewer than 5 frames (for example when stack traces
are disabled), length - 5 is negative and the scheduled leak-detection task
throws NegativeArraySizeException instead of logging the leak. Clamp the trimmed
length to zero and skip the copy when empty. Adds a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant