Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

A Heisenbug

DZone's Guide to

A Heisenbug

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Wikipedia defines a Heisenbug as:

A software bug that seems to disappear when one attempts to study it.

Sometimes one has these nightmare debugging sessions where you can prove that the bug can’t happen. But it still does. But I have rarely seen real Heisenbugs. Here is the story of one.

A Coworker once called me to his machine and showed our application and how it failed with a NullPointerException. Then he ran the application in the debugger, stepping through the code and the application just worked.

He could repeat this feat as often as he wanted. The perfect Heisenbug. So what was going on?

Well after a lot of really hard swearing thinking we found the following: The bug was caused by accessing the field of a property in a Hibernate entity directly, and not through its getter. So the field was lazy loaded and uninitialized and contained NULL, causing the NPE.

Why did it disappear in the debugger? There was an inspection showing the value returned by the getter. So on the first stop in the debugger the getter was called, Hibernate magic came to life, the field was populated and everything worked like a charm.

The moral of the story?

Don’t know. Software development sucks? Hibernate sucks?

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}