I built a CLI tool that explains Java stack traces and suggests fixes

java dev.to

Tired of Googling the same Java errors over and over?

I built StackLens, a CLI tool that analyzes your logs or stack traces and tells you what went wrong and how to fix it.

How it works

java -jar stacklens.jar analyze --text "java.lang.NullPointerException at UserService.java:42"
Enter fullscreen mode Exit fullscreen mode

Output:

Issue: NullPointerException
Severity: HIGH
Explanation: A method was called on a null object reference at UserService.java:42
Suggested Fix: Add null checks before accessing the object, or use Optional<T>
Enter fullscreen mode Exit fullscreen mode

You can also analyze a full log file:

java -jar stacklens.jar analyze --file app.log
Enter fullscreen mode Exit fullscreen mode

Or get JSON output to pipe into other tools:

java -jar stacklens.jar analyze --file app.log --format json
Enter fullscreen mode Exit fullscreen mode

What it detects

  • NullPointerException
  • OutOfMemoryError
  • Connection refused
  • Database connection failures
  • HTTP 500 errors
  • Thread pool exhaustion
  • Timeouts
  • Authentication errors

No Maven required

Linux/macOS:

curl -L https://github.com/AbaSheger/stacklens/releases/latest/download/stacklens.jar -o stacklens.jar
java -jar stacklens.jar analyze --text "your stack trace here"
Enter fullscreen mode Exit fullscreen mode

Windows (PowerShell):

Invoke-WebRequest-Uri"https://github.com/AbaSheger/stacklens/releases/latest/download/stacklens.jar"-OutFile"stacklens.jar"java-jarstacklens.jaranalyze--text"your stack trace here"
Enter fullscreen mode Exit fullscreen mode

Built with Java 17 + picocli. 51 unit tests. Open source.

GitHub: https://github.com/AbaSheger/stacklens

Would love feedback — especially on error types you'd want added.

Source: dev.to

arrow_back Back to Tutorials