Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6927

SystemProcedures.hasSchema can fail to close the resultset.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 10.12.1.1
    • Fix Version/s: None
    • Component/s: Services
    • Labels:
      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;
      

        Attachments

        1. derby.patch
          0.8 kB
          Hao Zhong

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              haozhong Hao Zhong
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: