BugTales Ep. 1: My code is broken, I don’t know why

The challenging journey full of superior bugs and magical code.

Let’s start a BugTales journey together. Let’s pick a problem, understand the symptoms and after that, take a closer look at the root cause of it. If we know the root cause of the problem, we can analyse and take actions to fix it.

The Call to Adventure

Here is the problem: We have a registration form on a webpage. One mandatory field in this dialog is missing. The customer raised a bug ticket and as always, you don’t have much time to fix this. Let’s assume you are new on this project and don’t have much knowledge about the codebase. But lucky you, you got all the necessary information and resources to work with.

The Challenge

Before you start thinking about reasons and solutions, let’s reproduce the problem first. I hope you always start with the reproduction. The fastest way to close a bug is to prove that there is none. Ok, you can reproduce it, let’s move on. The field is mandatory and should always be there, but it’s missing.

First thing you notice: there is no error message or any information, that something is going wrong on the page.

Hm, well let’s open the developer console and take a look there. It’s just empty.

Hmm, maybe something in the server log files. No, nothing that would help you in current situation. Ah, let’s change the log level to trace and try again. Good idea, but still nothing.

Hmmm, let’s take a look at the code. You take a deeper look and you are sure it should be somewhere around these three classes, but this code was not made to be read. You just don’t understand it at the moment.

Hmmmm, but we still have an ace up our sleeves. Let’s have a look at the last changes in the history. You know that this bug was not there two days ago. After checking out the older version and trying it out… yes, the bug is not there. Ok, we have reduced the amount of changes to look at. You see one giant commit with the message “refactoring” and after that… five commits with messages like “fix typo”. Wow, great. And the best thing is: this developer is on vacation for the next two weeks.

Hmmmmm, that’s enough. Time to get the big toys out of our bag. System.out … not effective in this case, next. Profiler … we don’t have a performance issue, next. Debugger … ouuu yes, let’s set breakpoints and debug the hell out of it.

The Threshold

You found it! Finally! The fix was simple, the way to it was not. Most importantly, our customer is happy. Mission accomplished. The realm is saved. The sun is shining. You are happy.

Mmmmmmh, you have a small, strange feeling about the amount of effort necessary to find this simple bug, but this is a story for another day.