Skip to content

Commit e8201a9

Browse files
author
alafighting
committed
增加非空判断
1 parent f2eb436 commit e8201a9

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

library/src/main/java/com/im4j/kakacache/rxjava/core/disk/storage/FileDiskStorage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public boolean isClosed() {
8888

8989
@Override
9090
public void remove(String key) throws CacheException {
91+
if (Utils.isEmpty(key)) {
92+
return;
93+
}
9194
try {
9295
delete(new File(mStorageDir, key));
9396
} catch (IOException e) {
@@ -125,6 +128,9 @@ private long countSize(File file) {
125128
}
126129

127130
public void delete(File file) throws IOException {
131+
if (file == null) {
132+
return;
133+
}
128134
// If delete() fails, make sure it's because the file didn't exist!
129135
if (!file.delete() && file.exists()) {
130136
throw new IOException("failed to delete " + file);

library/src/main/java/com/im4j/kakacache/rxjava/core/memory/journal/LRUMemoryJournal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void put(String key, CacheEntry entry) {
3939
@Override
4040
public boolean containsKey(String key) {
4141
CacheEntry entry = mKeyValue.get(key);
42-
return entry != null && !entry.isExpiry();
42+
return entry != null;
4343
}
4444

4545
@Override

library/src/main/java/com/im4j/kakacache/rxjava/core/memory/storage/SimpleMemoryStorage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public boolean isClosed() {
5959

6060
@Override
6161
public void remove(String key) throws CacheException {
62+
if (Utils.isEmpty(key)) {
63+
return;
64+
}
6265
mStorageMap.remove(key);
6366
}
6467

@@ -78,6 +81,10 @@ public long getTotalSize() {
7881
}
7982

8083
private static long countSize(Object value) {
84+
if (value == null) {
85+
return 0;
86+
}
87+
8188
// FIXME 更优良的内存大小算法
8289
long size = 1;
8390
if (value instanceof MemorySizeOf.SizeOf) {

0 commit comments

Comments
 (0)