Bad exception handling in OracleDatabase.setConnection

Description

We get this message using Oracle:

"Could not set remarks reporting on OracleDatabase: <exception message>"

I was digging around trying to determine why that happens. Apparently this occurs in OracleDatabase.setConnection. That method attempts to use reflection to find the method "getRemarksReporting" on the connection. However, our Connection does not have that method.

The comment in the catch indicates "that is OK". However, if that happens, then there are two lines of code that are skipped, and I assume those two lines are important.

This is what that method currently looks like:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Override public void setConnection(DatabaseConnection conn) { try { Method wrappedConn = conn.getClass().getMethod("getWrappedConnection"); wrappedConn.setAccessible(true); Connection sqlConn = (Connection) wrappedConn.invoke(conn); Method method = sqlConn.getClass().getMethod("setRemarksReporting", Boolean.TYPE); method.setAccessible(true); method.invoke(sqlConn, true); reservedWords.addAll(Arrays.asList(sqlConn.getMetaData().getSQLKeywords().toUpperCase().split(",\\s*"))); reservedWords.addAll(Arrays.asList("GROUP", "USER", "SESSION","PASSWORD", "RESOURCE", "START", "SIZE", "UID", "DESC")); //more reserved words not returned by driver } catch (Exception e) { LogFactory.getLogger().info("Could not set remarks reporting on OracleDatabase: " + e.getMessage()); ; //cannot set it. That is OK } super.setConnection(conn); }

I believe this would be a better implementation:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Override public void setConnection(DatabaseConnection conn) { try { Method wrappedConn = conn.getClass().getMethod("getWrappedConnection"); wrappedConn.setAccessible(true); Connection sqlConn = (Connection) wrappedConn.invoke(conn); Method method = sqlConn.getClass().getMethod("setRemarksReporting", Boolean.TYPE); method.setAccessible(true); method.invoke(sqlConn, true); } catch (Exception e) { LogFactory.getLogger().info("Could not set remarks reporting on OracleDatabase: " + e.getMessage()); ; //cannot set it. That is OK } reservedWords.addAll(Arrays.asList(sqlConn.getMetaData().getSQLKeywords().toUpperCase().split(",\\s*"))); reservedWords.addAll(Arrays.asList("GROUP", "USER", "SESSION","PASSWORD", "RESOURCE", "START", "SIZE", "UID", "DESC")); //more reserved words not returned by driver super.setConnection(conn); }

Environment

Linux, Oracle

Status

Assignee

Unassigned

Reporter

Robert Huffman

Labels

None

Components

Fix versions

Affects versions

3.3.1
3.3.0

Priority

Major