This post is not about discouraging debugging your code. Hee Hee!!! This is one of the lessons I learned recently.

My issue:
I had to execute an SQL query and print the resultset. I was starting the implementation and I wanted to see the output of the query. We usually work on two machines. One for dev and another for test. So, I ran my program on my test machine and connected to that process through eclipse (Remote Debugging). I got a NullPointerException in the code when I started traversing through the resultset.

Code is something like this: (Dont look at the syntax)
Statement stmt = conn.CreateConnection();
ResultSet rs = stmt.executeQuery(“My SQL Query here.”);
while(rs.next()) {
I print the values here.
}

When I the ran the code, I got a NullPointerException in the while loop. ie. rs.next(). But, rs it NOT null. So, I tried invoking some other methods in rs. ie. rs.first(), rs.findColumn() and all. Result was either a NullPointerException or ResultSet already closed exception. I could not figure out what is going wrong. That exception was thrown from inside the ResultSet Object. As the jdbc driver I used is not open source, I could not look into it. I spent almost a day on this issue. Wasted some network bandwidth.. Pinged somebody.. tortured somebody.. disturbed somebody.. No help!!!

After some time, by mistake, I executed the code and I forgot to launch the debugger. To my surprise, my code went through like charm. Suddenly I remembered reading (while utilizing the network bandwidth) that the resultset might be garbage collected.

My guess: For some reason, my resultset got garbage collected when I was debugging. But when I ran the code, it worked fine.

If you know the exact answer, please leave a comment. You will be blessed in this life and next 🙂

Advertisements