Question 432 of 481
Debug NullPointerException with -g Compiler Flag
Consider a Java application that throws a NullPointerException deep inside a library method. The stack trace does not include the caller's line numbers because the library was compiled without debug information. Which approach would best help identify the root cause?
Quick Answer
The correct answer is to recompile the library with the -g flag and redeploy. This works because the -g flag instructs the Java compiler to include full debug information—specifically line numbers, local variable names, and source file details—directly into the compiled class files. Without this debug metadata, the JVM cannot map bytecode instructions back to specific source lines, resulting in a stack trace that shows only method names and not the exact line where the NullPointerException occurred. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of how the compiler’s debug options affect runtime diagnostics; a common trap is assuming you can fix the exception by changing the code logic rather than by enabling debug symbols. Remember the mnemonic: “No -g, no line—trace is blind, fix the compile, find the line.”
⚠ Common exam trap
Oracle often tests the misconception that adding a try-catch or logging around the call site can reveal the internal cause of an exception, when in fact only the library's own debug information (or recompilation with `-g`) can provide the line-level detail needed to trace the root cause.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Recompile the library with -g flag and redeploy.
Recompiling the library with the `-g` flag includes debug information (such as line numbers and local variable names) in the class files. This allows the JVM to produce a stack trace with precise line numbers, enabling you to trace the NullPointerException back to the exact source line in the library code, even though the library was originally compiled without debug info.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a debugger to set breakpoints in the library.
Why it's wrong here
This requires source code and knowledge of where to break, which may not be available.
- ✓
Recompile the library with -g flag and redeploy.
Why this is correct
The -g flag generates debugging information including line numbers, making stack traces more informative.
- ✗
Use logging statements in the application code before and after the call.
Why it's wrong here
This can help but is less direct and may not pinpoint the exact location in the library.
- ✗
Add a try-catch around the library call and print the stack trace.
Why it's wrong here
The stack trace still lacks line numbers, so this does not provide additional information.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A developer is debugging a Java application that throws a NullPointerException. Which two actions help identify the source of the exception? (Choose two.)
medium- A.Use System.out.println statements
- ✓ B.Use a debugger to step through code
- ✓ C.Examine the stack trace
- D.Recompile with -g flag
- E.Catch the exception and print its message
Why B: To identify the source of a NullPointerException, the most effective actions are examining the stack trace (option C) and using a debugger (option B). The stack trace shows the exact line number and method call sequence where the exception occurred, pinpointing the location. A debugger allows you to step through code, inspect variable states, and observe the flow leading to the null reference. While System.out.println (A), catching the exception and printing its message (E), and recompiling with -g (D) can provide debugging information, they are not as direct or efficient for locating the root cause; notably, catching the exception does not prevent it and only prints the message without full stack details.
Last reviewed: Jun 30, 2026
This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.