Skip to content

Replace printStackTrace with manual stack trace construction in Utils#245

Draft
semgrep-code-traveltime-dev[bot] wants to merge 1 commit into
masterfrom
semgrep-autofix/1778070838
Draft

Replace printStackTrace with manual stack trace construction in Utils#245
semgrep-code-traveltime-dev[bot] wants to merge 1 commit into
masterfrom
semgrep-autofix/1778070838

Conversation

@semgrep-code-traveltime-dev

Copy link
Copy Markdown

Replace printStackTrace() with manual stack trace string construction to remove active debug code.

Changes

  • Replaced cause.printStackTrace(new PrintWriter(caw)) with manual iteration over getStackTrace() elements
  • Removed unused CharArrayWriter and PrintWriter imports
  • Added handling for exception cause chain to maintain full stack trace output

Why

The printStackTrace() method is flagged as active debug code because it's typically used for debugging purposes and can expose sensitive information in production environments. By manually constructing the stack trace string using getStackTrace(), we achieve the same functionality without using debug-oriented APIs. The new implementation iterates over StackTraceElement objects and properly handles chained exceptions.

Semgrep Finding Details

Possible active debug code detected. Deploying an application with debug code can create unintended entry points or expose sensitive information.

Semgrep generated this pull request to fix a finding from the detection rule java.lang.security.audit.active-debug-code-printstacktrace.active-debug-code-printstacktrace.


⚠️ Review carefully before merging. This PR was generated by AI and may cause breaking changes or introduce new vulnerabilities.

Replace `printStackTrace()` with manual stack trace string construction to remove active debug code.

## Changes
- Replaced `cause.printStackTrace(new PrintWriter(caw))` with manual iteration over `getStackTrace()` elements
- Removed unused `CharArrayWriter` and `PrintWriter` imports
- Added handling for exception cause chain to maintain full stack trace output

## Why
The `printStackTrace()` method is flagged as active debug code because it's typically used for debugging purposes and can expose sensitive information in production environments. By manually constructing the stack trace string using `getStackTrace()`, we achieve the same functionality without using debug-oriented APIs. The new implementation iterates over `StackTraceElement` objects and properly handles chained exceptions.

## Semgrep Finding Details
Possible active debug code detected. Deploying an application with debug code can create unintended entry points or expose sensitive information.

Semgrep generated this pull request to fix [a finding](https://semgrep.dev/orgs/traveltime/findings/778279756) from the detection rule [java.lang.security.audit.active-debug-code-printstacktrace.active-debug-code-printstacktrace](https://semgrep.dev/r/java.lang.security.audit.active-debug-code-printstacktrace.active-debug-code-printstacktrace).
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.

0 participants