After trying the new SSL functionality in the driver I stumbled upon the
following bug in PSQLException:
The no-parameter constructor of SQLException is called at the beginning of every
constructor in PSQLException. This can lead to a NullPointerException
if the user has set the loglevel to something > 0. When loglevel is
greater than 0 Driver.java calls DriverManager.setLogWriter(System.out).
All messages are printed to this logwriter. The no-parameter
constructor for SQLException prints the stacktrace of the current
exception to this logwriter whenever it is instantiated. Since
PSQLException inherits from SQLException the toString method of
PSQLException will return null since the translate method won't have
been called yet.
As a consequence an attempt will be made to print the return value from
toString() to the logwriter and this will result in a
NullPointerException being thrown. This might be categorized as a bug in
PrintWriter but any user trying to use the jdbc driver with loglevel > 0
might stumble upon it.
I've cooked up a JUnit testcase that checks for the error and I've made a
simple one-liner patch to get toString() to return "" if message hasn't been
initialized yet.
--
Tarjei Skorgenes
tarjei.skorgenes@himolde.no