Skip to content
cccskills
FreePublished on GitHubEnglish overview

java-debugging

Investigate Java exceptions, incorrect behavior, and failing tests through reproducible checks and focused hypotheses. Use logs, stack traces, and debugger connections to inspect execution, identify the cause, and add a regression test.

OriginalShow the original description

Debug Java applications systematically: JDWP remote debugging, jdb, VS Code and IntelliJ attach, debugging Maven/Gradle tests, Spring Boot and Quarkus dev mode, containers, breakpoints/logpoints, and reading stack traces. Use when the user needs to find the cause of a Java bug, exception, wrong behavior, or failing test, or asks how to attach a debugger.

Works withKubernetes

Run score Not tested

See how to install

Good for

  • Investigating Java exceptions and incorrect behavior
  • Debugging failing Maven or Gradle tests
  • Attaching a debugger with VS Code or IntelliJ IDEA
  • Debugging applications in development containers

Overview

What it does

java-debugging helps investigate Java application problems by reproducing them and testing one hypothesis at a time. It explains how to read stack traces, use logs and logpoints, and inspect execution with breakpoints when needed. It also covers debugger connections with jdb, VS Code, and IntelliJ IDEA, as well as investigation steps for Maven and Gradle tests, Spring Boot, Quarkus, and containers.

When it helps

Use it when an exception has no clear cause, a test fails, or logs do not show how execution reached the problem. The workflow narrows the issue to a small reproducible case, checks the suspected cause, adds a test to help prevent recurrence, and removes temporary logs or debug settings.

Example requests

  • “Find the cause of this NullPointerException.”
  • “Help me trace this failing Maven test with a debugger.”
  • “Show me how to attach IntelliJ IDEA to the Java app in my development container.”

Notes

Debugger connections require a suitable JDK and the IDE or tool you plan to use. Do not expose debug ports publicly; use a tunnel for remote connections. Production connections are made only when explicitly requested. Settings vary by JDK and Gradle version, and pausing execution can affect timing or trigger timeouts.

This overview was written by AI (OpenAI Codex) from the public SKILL.md. Check the original below for the exact behavior.

Document check

AI checked the SKILL.md for operations that need care and for setup requirements. The score comes only from actually running the skill (hands-on test).

SafetyAre sending data, deleting files, and running commands disclosed?
AGoodIt requires loopback binding, tunnels, and explicit instruction for production access.
Easy setupDoes it need few tools or API keys, and are they documented?
BPartly lackingA JDK and IDE are needed, but installation steps are not provided.

Not counted in the score. Rated by AI (OpenAI Codex) as of Oct 25, 2026. Treat it as a guide and read the original before installing.

Disagree? Request a re-evaluation

Tell us which point is wrong and why. No login needed. We will check it against the SKILL.md, redo the evaluation, and show the result here.

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

Files included (2)

  • SKILL.md8.3 KB
  • references/stack-traces.md1.6 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Java Debugging

Find the root cause of a Java defect with a reproducible, hypothesis-driven loop, and attach a debugger safely when logs are not enough.

Safety rules

  • Bind JDWP to loopback only (127.0.0.1). Never bind *:5005 on a reachable network; use an SSH tunnel or kubectl port-forward for remote hosts.
  • Use suspend=n for running applications. suspend=y is acceptable only for short local test runs bound to loopback (waiting for the IDE to attach). Never leave a debug agent enabled on production; JDWP gives full code execution to whoever connects.
  • Do not attach a debugger to production without explicit user instruction. Prefer reproducing locally or use read-only diagnostics (see the java-diagnostics skill).
  • JAVA_TOOL_OPTIONS is picked up by every JVM started in that environment (build tools, forked test JVMs, child processes), causing Address already in use clashes. Prefer scoping the flag to the one process you want to debug.

Method

Reproduce deterministically, minimize, read the evidence (stack traces), test one falsifiable hypothesis with the least intrusive tool (log line or logpoint before breakpoints), then add a regression test and remove debug flags and temporary logging.

Version-dependent behavior (verified)

  • Helpful NullPointerException messages (JEP 358) are off by default in JDK 14 (-XX:+ShowCodeDetailsInExceptionMessages) and on by default from JDK 15 (JEP 358 documents the message format). Source: https://openjdk.org/jeps/358.
  • JDWP bare address=5005 binds all interfaces before JDK 9 and loopback from JDK 9 (see below).
  • Gradle --debug-jvm passes a bare address, so on JDK 8 it listens on all interfaces.

Attach a debugger (JDWP)

Start the JVM:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 -jar app.jar

Always write the explicit 127.0.0.1:5005 on every JDK version: a bare address=5005 listens on all interfaces before JDK 9 and only on loopback from JDK 9. On JDK 8 and older, the host:port form may not be honored, so also restrict access with a firewall or tunnel.

Attach with jdb:

jdb -attach 127.0.0.1:5005
# stop in com.example.OrderService.place | stop at com.example.OrderService:42
# cont | next | step | locals | print order | where | catch java.lang.NullPointerException

VS Code (Extension Pack for Java)

.vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "Attach to JVM",
      "request": "attach",
      "hostName": "127.0.0.1",
      "port": 5005
    }
  ]
}

IntelliJ IDEA

Run | Edit Configurations | + | Remote JVM Debug; host 127.0.0.1, port 5005, debugger mode Attach. The dialog shows the matching JVM argument string.

Debug tests and frameworks

ScenarioCommand (port 5005)
Maven Surefire unit testmvn test -Dmaven.surefire.debug -Dtest=OrderServiceTest
Maven Failsafe ITmvn verify -Dmaven.failsafe.debug -Dit.test=OrderIT
Gradle testgradle test --debug-jvm --tests '*OrderServiceTest'
Spring Boot (Maven)mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005"
Spring Boot (Gradle)Configure bootRun as below, then gradle bootRun (loopback, no suspend)
Quarkus dev modemvn quarkus:dev (debug port 5005 open by default; -Ddebug=5006 changes it, -Ddebug=false disables)

Surefire/Failsafe debug mode and --debug-jvm suspend until a debugger attaches, which is fine for a local run. Surefire and Failsafe accept a custom agent string instead of the bare flag, e.g. -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:5005". Verified listeners on 127.0.0.1 (via lsof -nP -iTCP:5005 -sTCP:LISTEN) for Gradle 9.7 --debug-jvm, Maven Surefire 3.5 -Dmaven.surefire.debug and Quarkus 3.40 dev mode on JDK 26; Gradle 7.6.4, 8.0.2 (JDK 17), 8.5 (JDK 21) and 8.14.3 also listened on 127.0.0.1. Gradle passes a bare address=5005 (no host), so the bind address comes from the JDK: loopback on JDK 9+, but all interfaces (0.0.0.0:5005, checked in an eclipse-temurin:8-jdk container with Gradle 7.6.4 and 8.14.3) on JDK 8. Older Gradle/plugin versions were not tested; run the same lsof check and use an explicit loopback agent on shared networks or JDK 8.

Explicit Gradle configuration (Gradle 7.6+; debugOptions.host was added in 7.6; Kotlin DSL):

tasks.withType<Test> {
    debugOptions { enabled.set(true); host.set("127.0.0.1"); port.set(5005); server.set(true); suspend.set(true) }
}

// BootRun extends JavaExec, not Test; configure it separately when the Boot plugin is applied.
tasks.named<JavaExec>("bootRun") {
    debugOptions { enabled.set(true); host.set("127.0.0.1"); port.set(5005); server.set(true); suspend.set(false) }
}

Then run gradle test --tests '*OrderServiceTest' or gradle bootRun, without --debug-jvm (which enables suspension). Configure only the task you are debugging; do not run both listeners on port 5005 at once. For Gradle before 7.6, use jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005") on the target task instead (suspend=y for local tests), without also enabling debugOptions or --debug-jvm. On JDK 8 and older, retain the firewall/tunnel precaution above.

Containers

Publish the port to loopback only and let the JVM listen inside the container:

docker run --rm -p 127.0.0.1:5005:5005 \
  -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" my-app

Inside the container the agent must bind * for the port mapping to work, so JDWP (full code execution) is reachable by every other container on the same Docker network; the 127.0.0.1: mapping only blocks access from other hosts. Use this only on a developer machine where no untrusted containers share the network: run it on a dedicated user-defined network (not the shared default bridge) containing only this container, or keep the agent on 127.0.0.1 inside the container and reach it with docker exec/kubectl port-forward style forwarding instead of publishing it. For Kubernetes use kubectl port-forward pod/<name> 5005:5005 against a dev/staging pod only.

Common pitfalls

  • Hot code replace only swaps method bodies; adding/removing methods or fields or changing signatures needs a restart (or Quarkus dev mode / Spring DevTools).
  • Missing debug info: code compiled without -g shows unavailable variables (Maven and Gradle include it by default). In lambdas, step into the lambda body.
  • Heisenbugs/races: pausing changes timing. Prefer logpoints, thread dumps, or JFR; suspend only the current thread, not all threads.
  • Async and reactive code: stack traces show scheduler frames, not the caller. Use IDE async stack traces, correlation IDs, or Reactor Hooks.onOperatorDebug() in dev only.
  • Virtual threads (JDK 21+): there can be thousands; use jcmd <pid> Thread.dump_to_file -format=json file.json for an overview.
  • Timeouts: long pauses can trip HTTP, DB, or heartbeat timeouts; raise them locally.
  • toString() side effects: debugger evaluation calls toString(), which may trigger lazy loading or mutate state.

Optional code-navigation aid

If the Copilot CLI lsp tool is configured (see the lsp-setup skill), go-to-definition, find-references, and call hierarchy help trace the execution path. It is optional; grep and reading code work as well.

References

  • Reading stack traces
  • For runtime symptoms (CPU, memory, deadlocks, slow startup) use the java-diagnostics skill.

Official tool docs (prefer them over this skill for the JDK in use; change 21 to your version): jcmd https://docs.oracle.com/en/java/javase/21/docs/specs/man/jcmd.html, JDK troubleshooting guide https://docs.oracle.com/en/java/javase/21/troubleshoot/.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Map an existing codebase into seven documents covering its technology, structure, architecture, conventions, integrations, tests, and concerns. Link findings to file evidence, mark unknowns, and highlight differences between stated plans and the actual implementation.

  • Get oriented in an unfamiliar codebase
  • Prepare documentation for a project handover
  • Compare documented architecture with implementation
github/awesome-copilot40.4KUpdated Oct 24, 2026

Assess a repository’s readiness for AI agents with AgentRC and generate a standalone HTML dashboard. Review scores across nine areas, see prioritized improvements, and optionally apply scoring policies tailored to an organization.

  • Assessing a repository’s readiness for AI agents
  • Prioritizing improvements from assessment results
  • Reviewing scores under an organization’s own policy
github/awesome-copilot40.4KUpdated Oct 24, 2026

Generate coding agent instruction files from a project's actual code using AgentRC. Capture detected languages, frameworks, and conventions in one shared file or split rules by topic and project area, with a preview before writing.

  • Create project instructions for VS Code Copilot
  • Refresh agent rules after project changes
  • Split monorepo instructions by project area
github/awesome-copilot40.4KUpdated Oct 24, 2026

Customize AgentRC readiness assessments to match team or organization standards. Choose or create policies that adjust check importance, disable irrelevant checks, set pass thresholds, and define requirements for automated checks in CI workflows.

  • Set shared readiness standards across an organization
  • Focus assessments on AI tooling
  • Adjust the importance of individual checks
github/awesome-copilot40.4KUpdated Oct 24, 2026

Analyze supplied ad performance data to identify wasted spend, strong campaigns, and next tests. Compare channels, assess whether test differences are meaningful, and produce budget reallocation recommendations with a prioritized action plan.

  • Identify ads and keywords to pause
  • Find campaigns and audiences worth scaling
  • Assess whether A/B test results are meaningful
github/awesome-copilot40.4KUpdated Oct 24, 2026

Turn code files into learning resources by adding comments that explain syntax, programming concepts, and design choices. Adjust explanation depth and repetition to the reader’s knowledge while preserving file structure, encoding, and syntax.

  • Add beginner-friendly explanations to existing code
  • Document the reasoning behind syntax and design choices
  • Adjust comment depth for readers with different experience
github/awesome-copilot40.4KUpdated Oct 24, 2026

See all skills by github

Report a problem with this skill