Skip to content

Commit

Permalink
Fix for a NullPointerException on first run. (openwallet-foundation-l…
Browse files Browse the repository at this point in the history
…abs#453)

Signed-off-by: Peter Sorotokin <[email protected]>
  • Loading branch information
sorotokin authored Jan 23, 2024
1 parent 33408e2 commit 06fe0d3
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ public void delete(@NonNull String key) {

@Override
public void deleteAll() {
for (File file : mStorageDirectory.listFiles()) {
File[] fileList = mStorageDirectory.listFiles();
if (fileList == null) {
return;
}
for (File file : fileList) {
String name = file.getName();
if (!name.startsWith(PREFIX)) {
continue;
Expand All @@ -207,16 +211,19 @@ public void deleteAll() {
@NonNull
public Collection<String> enumerate() {
ArrayList<String> ret = new ArrayList<>();
for (File file : mStorageDirectory.listFiles()) {
String name = file.getName();
if (!name.startsWith(PREFIX)) {
continue;
}
try {
String decodedName = URLDecoder.decode(name.substring(PREFIX.length()), "UTF-8");
ret.add(decodedName);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
File[] fileList = mStorageDirectory.listFiles();
if (fileList != null) {
for (File file : fileList) {
String name = file.getName();
if (!name.startsWith(PREFIX)) {
continue;
}
try {
String decodedName = URLDecoder.decode(name.substring(PREFIX.length()), "UTF-8");
ret.add(decodedName);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
}
return ret;
Expand Down

0 comments on commit 06fe0d3

Please sign in to comment.