db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Pendleton (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6927) SystemProcedures.hasSchema can fail to close the resultset.
Date Sat, 25 Mar 2017 14:59:42 GMT

    [ https://issues.apache.org/jira/browse/DERBY-6927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15941751#comment-15941751
] 

Bryan Pendleton commented on DERBY-6927:
----------------------------------------

Yes, that sounds like an interesting project, and the observation it made about the similarity
of the two pieces of code and the likely implied flaw seems valid to me.

I look forward to additional such findings produced by your tool!


> SystemProcedures.hasSchema can fail to close the resultset.
> -----------------------------------------------------------
>
>                 Key: DERBY-6927
>                 URL: https://issues.apache.org/jira/browse/DERBY-6927
>             Project: Derby
>          Issue Type: Bug
>          Components: Services
>    Affects Versions: 10.12.1.1
>            Reporter: Hao Zhong
>         Attachments: derby.patch
>
>
> The SystemProcedures.hasSchema method has the following code:
> {code:title=SystemProcedures.java|borderStyle=solid}
>  ResultSet rs = conn.getMetaData().getSchemas();
>         boolean schemaFound = false;
>         while (rs.next() && !schemaFound)
>             schemaFound = schemaName.equals(rs.getString("TABLE_SCHEM"));
>         rs.close();
> {code}
> 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:
> {code:title=AccessDatabase.java|borderStyle=solid}
> boolean found=false;
>     	ResultSet result = conn.getMetaData().getSchemas();
>     	while(result.next()){
>     		if(result.getString(1).equals(schema)){
>     			found=true;
>     			break;
>     		}
>     	}	
>     	return found;
> {code}
> The fixed code ensures that result is closed:
> {code:title=AccessDatabase.java|borderStyle=solid}
> 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;
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message