Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
10.12.1.1
-
None
-
None
Description
The SystemProcedures.hasSchema method has the following code:
SystemProcedures.java
ResultSet rs = conn.getMetaData().getSchemas(); boolean schemaFound = false; while (rs.next() && !schemaFound) schemaFound = schemaName.equals(rs.getString("TABLE_SCHEM")); rs.close();
The while statement can throw exceptions, so the rs.close can never be executed. Indeed, DERBY-6297 fixed a similar bug. The buggy code is:
AccessDatabase.java
boolean found=false; ResultSet result = conn.getMetaData().getSchemas(); while(result.next()){ if(result.getString(1).equals(schema)){ found=true; break; } } return found;
The fixed code ensures that result is closed:
AccessDatabase.java
ResultSet result = conn.getMetaData().getSchemas(); try { while (result.next()) { if (result.getString(1).equals(schema)) { // Found it! return true; } } } finally { result.close(); } // Didn't find the schema. return false;