HHH-9136 - DatabaseMetadata: NPE hides exception in finally block

- Protection against NPE in finally block
- Little formatting fixes
This commit is contained in:
msulima 2014-04-20 14:12:20 +02:00 committed by Brett Meyer
parent 9bd6917d0d
commit 3b18c275ea
1 changed files with 23 additions and 18 deletions

View File

@ -55,7 +55,7 @@ import org.jboss.logging.Logger;
*/ */
public class DatabaseMetadata { public class DatabaseMetadata {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, DatabaseMetaData.class.getName()); private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, DatabaseMetaData.class.getName());
private final Map tables = new HashMap(); private final Map tables = new HashMap();
private final Set sequences = new HashSet(); private final Set sequences = new HashSet();
@ -157,7 +157,9 @@ public class DatabaseMetadata {
} }
finally { finally {
rs.close(); if ( rs != null ) {
rs.close();
}
} }
} }
catch (SQLException sqlException) { catch (SQLException sqlException) {
@ -187,10 +189,13 @@ public class DatabaseMetadata {
} }
} }
finally { finally {
rs.close(); if ( rs != null ) {
statement.close(); rs.close();
}
if ( statement != null ) {
statement.close();
}
} }
} }
} }
} }
@ -203,30 +208,30 @@ public class DatabaseMetadata {
return false; return false;
} }
public boolean isTable(Object key) throws HibernateException { public boolean isTable(Object key) throws HibernateException {
if(key instanceof String) { if(key instanceof String) {
Table tbl = new Table((String)key); Table tbl = new Table((String)key);
if ( getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null ) { if ( getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null ) {
return true; return true;
} else { } else {
String[] strings = StringHelper.split(".", (String) key); String[] strings = StringHelper.split(".", (String) key);
if(strings.length==3) { if(strings.length==3) {
tbl = new Table(strings[2]); tbl = new Table(strings[2]);
tbl.setCatalog(strings[0]); tbl.setCatalog(strings[0]);
tbl.setSchema(strings[1]); tbl.setSchema(strings[1]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null; return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
} else if (strings.length==2) { } else if (strings.length==2) {
tbl = new Table(strings[1]); tbl = new Table(strings[1]);
tbl.setSchema(strings[0]); tbl.setSchema(strings[0]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null; return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
} }
} }
} }
return false; return false;
} }
@Override @Override
public String toString() { public String toString() {
return "DatabaseMetadata" + tables.keySet().toString() + sequences.toString(); return "DatabaseMetadata" + tables.keySet().toString() + sequences.toString();
} }
} }