liveBook · Manning

Root cause

As explained in Troubleshooting Java, Second Edition

The underlying reason a software behavior or failure occurs.

A root cause is the underlying reason a software behavior or failure occurs. The visible exception location may only be a consequence, so investigate what happened earlier before changing that line. section 4.1.1

Use root-cause investigation to:

  • Start with logs and exception stack traces, then continue with a debugger, profiler, or other suitable technique. section 4.1.1
  • Ask why the failing reference, value, or behavior occurred instead of immediately adding local conditionals or exception handlers. section 4.1.1
  • Reproduce the failure when possible, both to investigate it and to verify the eventual solution. section 1.5

A misleading NullPointerException

A log reports a NullPointerException inside a worker thread. The exception identifies where execution failed, but the missing reference may result from an earlier instruction that behaved unexpectedly. Investigate that earlier behavior rather than hiding the symptom with a try-catch or if-else. section 4.1.1

java.lang.NullPointerException
at java.base/java.util.concurrent.ThreadPoolExecutor
➥runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker
➥run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable
➥run(TaskThread.java:61) ~[tomcat-embed-core-9.0.26.jar:9.0.26]
at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]

Use the stack trace to locate the failing execution path and identify which methods called it. section 4.3

How Troubleshooting Java, Second Edition covers it

How deep it goes
Distinguishes symptoms from causes and outlines a multi-tool investigation, but does not provide a complete diagnostic procedure.
Examples
Uses NullPointerException stack traces and deadlock thread dumps as diagnostic examples.
What it assumes
Assumes basic familiarity with application failures while clarifying that an exception location is not necessarily its cause.
What you can do after
Diagnose/debug with it by tracing failures beyond their visible exceptions and selecting further investigation techniques.
How it connects
Connects logs, exception stack traces, debuggers, profilers, reproduction, and thread dumps.

Also explained in

Compare how 5 books explain root cause →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.