Over a million developers have joined DZone.

A Heisenbug

DZone's Guide to

A Heisenbug

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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?

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.


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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}