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 d7173eeb3a
commit 3ad914d73f
1 changed files with 23 additions and 18 deletions

View File

@ -53,7 +53,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();
@ -148,7 +148,9 @@ public class DatabaseMetadata {
} }
finally { finally {
rs.close(); if ( rs != null ) {
rs.close();
}
} }
} }
catch (SQLException sqlException) { catch (SQLException sqlException) {
@ -179,10 +181,13 @@ public class DatabaseMetadata {
} }
} }
finally { finally {
rs.close(); if ( rs != null ) {
statement.close(); rs.close();
}
if ( statement != null ) {
statement.close();
}
} }
} }
} }
} }
@ -195,30 +200,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();
} }
} }