Prevent NullPointerException exceptions in SimpleCache initialization

This is a temporary fix to prevent NullPointerException exceptions.
Though writing to cache will still fail if the cache folder isn't a real
folder.

There are a few thing we can try:
* The listing might be failing because the cache folder is just created.
We can wait and try again.
* If the cache folder is a regular file, we can try deleting and creating
a folder with the same name.

PiperOrigin-RevId: 234121925
This commit is contained in:
eguven 2019-02-15 12:39:51 +00:00 committed by Andrew Lewis
parent 8982da4b75
commit b69041bea2

View File

@ -582,15 +582,17 @@ public final class SimpleCache implements Cache {
* @throws IOException If there is an error loading or generating the UID. * @throws IOException If there is an error loading or generating the UID.
*/ */
private static long loadUid(File directory, File[] files) throws IOException { private static long loadUid(File directory, File[] files) throws IOException {
for (File file : files) { if (files != null) {
String fileName = file.getName(); for (File file : files) {
if (fileName.endsWith(UID_FILE_SUFFIX)) { String fileName = file.getName();
try { if (fileName.endsWith(UID_FILE_SUFFIX)) {
return parseUid(fileName); try {
} catch (NumberFormatException e) { return parseUid(fileName);
// This should never happen, but if it does delete the malformed UID file and continue. } catch (NumberFormatException e) {
Log.e(TAG, "Malformed UID file: " + file); // This should never happen, but if it does delete the malformed UID file and continue.
file.delete(); Log.e(TAG, "Malformed UID file: " + file);
file.delete();
}
} }
} }
} }