NPE in JtdsConnection on IOError connecting to SQL Server
Brought to you by:
ickzon
JtdsConnection can sometimes fail to connect to SQL Server, in this case, 2014, but throws a NullPointerException trying to format the response.
Caused by: java.lang.NullPointerException at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:432) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:208) at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:79)
It appears the error arises when an IOException is caught but it has no ErrorMessage. The code fragment is:
} catch (IOException e) { loginError = true; if (loginTimeout > 0 && e.getMessage().indexOf("timed out") >= 0) { throw Support.linkException( new SQLException(Messages.get("error.connection.timeout"), "HYT01"), e); } throw Support.linkException( new SQLException(Messages.get("error.connection.ioerror", e.getMessage()), "08S01"), e);
This is a network connection to SQL Server over TCP/IP. It's not the first time I've seen IOExceptions with no error message from the network layer. I don't believe it is specific to Java 8.