Coding to a Bug - No Fluff Just Stuff

Coding to a Bug

Posted by: Baruch Sadogursky on June 1, 2007

Well, the story goes like this.
Once you have a closed source application to extend (well, you decomiple it of course, but it doesn’t make it open source, do it?). And it is damn old (like 2001 or something, did people actually code then?). And it uses some weird database like MS SQL Server, and, of course a JDBC driver for it, jTDS. Back then, in 2001 version 1.0 of the jTDS was available. It was a little very buggy, for example, putting the driver’s jar in WEB-INF/libs generates NPE, so it have to live in Tomcat’s share lib.
And of course, as any respectable company the vendor of the application developed it’s own wrapper arround JDBC with DatabaseUtilities.getConnection, releaseConnection, and so on.

Now, to the story.
On the surface it looked easy. We obtain connection, bla-bla, executeQuery, ResultSet.hasNext, etc. Works like a charm on clearly installed application. Once they populate the database with their home-made utility for migration from excel… boom. Thier code works, our throws IOEXception – “system cannot find the path specified”. The root of the exception somewhere inside the driver. Google suggests to update the driver to the last version. No prob! Done. Of course I move it from Tomcat’s share to the application lib on that occasion.
Guess what? Our code works like charm, but all other updates in application start failing on it can’t manually commit when auto-commit is on! As I understood it, they just didn’t turn auto-commit off, and the old buggy driver forgave them!

What can you do? The old driver stops working on durty database, the new driver won’t work with their application code. You can’t change the source of their driver wrapper to turn the auto-commit off, because it is closed-source, and you can’t be sure decompiler did a perfect work (and usually it don’t).

Anyway, we rolled-back the driver version, returned it to Tomcat’s shared lib, and went to their JDBC wrapper to look which shaman ceremonies they perform to make it work. We’d better not. They cast the driver to the actual jTDS class and call all kind of implementation methods. I am thankful to them they wrapped all those inside their JDBC wrapper, so all we needed to do is to replace JDBC code with some really strange calls like getQueryResults, which gets the SQL string (not parametrized, of course), and returns array of strings (contatining all the data, including dates and numbers).

So, what do you say? Any better way to do it except coding to the bug?


Baruch Sadogursky

About Baruch Sadogursky

Baruch Sadogursky (@jbaruch) did Java before it had generics, DevOps before there was Docker, and DevRel before it had a name. He started DevRel at JFrog when it was ten people and took it all the way to a successful $6B IPO by helping engineers solve problems. Now Baruch keeps helping engineers solve problems but also helps companies help engineers solve problems. He is a co-author of the “Liquid Software” and “DevOps Tools for Java Developers” books, serves on multiple conference program committees, and regularly speaks at numerous most prestigious industry conferences, including Kubecon, JavaOne (RIP), Devoxx, QCon, DevRelCon, DevOpsDays (all over), DevOops (not a typo) and others. After a tenure of eleven years in JFrog DevRel, Baruch is the Principal Developer Productivity Engineering Advocate at Gradle.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »