#41 testException can loop on NPE

open
nobody
5
2008-11-06
2008-11-06
Ryan
No

The following code seems to fail to advance the iterator causing the loop to not never exit when an exception with a null message is encountered.

FatalSqlExceptionHelper:117
if (t.getMessage() != null && t.getMessage().indexOf((String) i.next()) > -1) {

I have patched the code in the following way to treat all Errors, RuntimeExceptions and Exceptions with null messages as fatal (since these are really not expected to be coming from the JDBC driver under "normal" error conditions), as well as fixing the loop to exit immediately when a null message or fatal exception is found (rather than completing the iteration).

protected static boolean testException(ConnectionPoolDefinitionIF cpd, Throwable t, int level) {
if (t instanceof Error || t instanceof RuntimeException) {
LOG.error("testException: unexpected Error or RuntimeException found - treating as fatal",t);
return true;
}

boolean fatalSqlExceptionDetected = false;
Iterator i = cpd.getFatalSqlExceptions().iterator();
while (i.hasNext()) {
if ((t.getMessage() == null) || (t.getMessage().indexOf((String) i.next()) > -1)) {
LOG.error("testException: fatal exception found - exiting check", t);
// This SQL exception indicates a fatal problem with this connection.
fatalSqlExceptionDetected = true;
break;
}
}

Discussion

  • Ryan
    Ryan
    2008-11-06

    Patched source file frm 0.9.1 release