Over a million developers have joined DZone.

A Heisenbug

DZone's Guide to

A Heisenbug

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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?

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Published at DZone with permission of Jens Schauder, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}