Check whether File#listFiles() returns null.

The docs say this can happen for a directory if there's an I/O error.
This commit is contained in:
akwizgran
2016-09-27 15:52:57 +01:00
parent eb6189150f
commit 53d0b8b21e
6 changed files with 32 additions and 10 deletions

View File

@@ -35,6 +35,7 @@ class H2Database extends JdbcDatabase {
+ ";WRITE_DELAY=0;DB_CLOSE_ON_EXIT=false";
}
@Override
public boolean open() throws DbException {
boolean reopen = config.databaseExists();
if (!reopen) config.getDatabaseDirectory().mkdirs();
@@ -42,6 +43,7 @@ class H2Database extends JdbcDatabase {
return reopen;
}
@Override
public void close() throws DbException {
// H2 will close the database when the last connection closes
try {
@@ -51,6 +53,7 @@ class H2Database extends JdbcDatabase {
}
}
@Override
public long getFreeSpace() throws DbException {
File dir = config.getDatabaseDirectory();
long maxSize = config.getMaxSize();
@@ -63,7 +66,9 @@ class H2Database extends JdbcDatabase {
private long getDiskSpace(File f) {
if (f.isDirectory()) {
long total = 0;
for (File child : f.listFiles()) total += getDiskSpace(child);
File[] children = f.listFiles();
if (children != null)
for (File child : children) total += getDiskSpace(child);
return total;
} else if (f.isFile()) {
return f.length();