Menu

#773 NPE in JtdsConnection on IOError connecting to SQL Server

v1.3
open
nobody
None
1
2018-03-25
2018-03-25
No

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.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.