Java Reference
In-Depth Information
Like runtime errors, the key to resolving logic errors is being able to peek
under the covers of the running program. By examining the contents of your
supposedly sorted list at each step of execution, you can try to determine the
issue at hand.
Race conditions
A race condition is a bug caused by an unexpected dependency on the relative tim-
ing of events. For example, if an instance variable is accessible by two threads
simultaneously, one thread may interfere with another's use of the class. While
this situation may not cause a problem every time you run your application, the
potential is always there. Bugs tied to race conditions only cause a problem when
the timing is just right (or just wrong, depending how you look at it). Race condi-
tions are often the result of threading problems; to help you find them, IDEA
gives you the ability to examine all of your application's threads when searching
for the problem.
The dreaded Heisenbug
As with particle physics, the attempt to examine a system tends to alter its behavior
in some way. Heisenbugs , a take-off on the Heisenberg uncertainty principle, are
bugs that seemingly disappear or change their appearance when you try to track
them down in the debugger. Although using a debugger is for the most part a non-
invasive process, be aware that it can affect your running code in terms of timing
and concurrency. In particular, applications will run slower under the debugger,
which may cause bugs to run for cover when you try to seek them out. Race con-
ditions and threading-related bugs are particularly susceptible to this effect.
6.1.2
Preparing your code for debugging
One nice thing about working with a debugger to root out problems is that you
aren't required to modify your source code, recompile, use a special VM , imple-
ment a magic interface, or write your code in any particular style. The debugger
takes advantage of monitoring technology built into the Java platform. You do,
however, have to follow a few rules to make sure that the debugger can operate
correctly with your classes.
Generating symbolic debugging information
When you build your application, the compiler converts all your pretty Java
code into a tight bundle of Java byte code. A debugger works by tracking the
byte code's execution and reporting on the original source code references that
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search