Skip to content

Commit 84055a0

Browse files
authored
Merge pull request #340 from JemyCheung/master
fix nullpointer
2 parents 8509d09 + 334a9ad commit 84055a0

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

library/library.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
100100
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
101101
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
102+
<excludeFolder url="jar://$MODULE_DIR$/build/qiniu-android-sdk-7.4.0.jar!/" />
102103
</content>
103104
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
104105
<orderEntry type="sourceFolder" forTests="false" />

library/src/main/java/com/qiniu/android/common/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
public final class Constants {
5-
public static final String VERSION = "7.4.0";
5+
public static final String VERSION = "7.4.1";
66

77
public static final String UTF_8 = "utf-8";
88
}

library/src/main/java/com/qiniu/android/http/DnsPrefetcher.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ public static boolean checkRePrefetchDns(String token, Configuration config) {
285285
String localip = AndroidNetwork.getHostIP();
286286
String akScope = StringUtils.getAkAndScope(token);
287287

288+
if (currentTime == null || localip == null || akScope == null)
289+
return true;
288290
long cacheTime = (Long.parseLong(currentTime) - Long.parseLong(cacheKey.getCurrentTime())) / 1000;
289-
if (!localip.equals(cacheKey.getLocalIp()) || cacheTime > config.dnsCacheTimeMs || !akScope.equals(cacheKey.getAkScope())) {
291+
if (!cacheKey.getLocalIp().equals(localip) || cacheTime > config.dnsCacheTimeMs || !cacheKey.getAkScope().equals(akScope)) {
290292
return true;
291293
}
292294

@@ -302,6 +304,8 @@ public static void startPrefetchDns(String token, Configuration config) {
302304
String currentTime = String.valueOf(System.currentTimeMillis());
303305
String localip = AndroidNetwork.getHostIP();
304306
String akScope = StringUtils.getAkAndScope(token);
307+
if (currentTime == null || localip == null || akScope == null)
308+
return;
305309
String cacheKey = new DnsCacheKey(currentTime, localip, akScope).toString();
306310
Recorder recorder = null;
307311
DnsPrefetcher dnsPrefetcher = null;
@@ -310,14 +314,18 @@ public static void startPrefetchDns(String token, Configuration config) {
310314
dnsPrefetcher = DnsPrefetcher.getDnsPrefetcher().init(token);
311315
} catch (IOException e) {
312316
e.printStackTrace();
317+
return;
313318
}
314319
if (config.dns != null) {
315320
DnsPrefetcher.getDnsPrefetcher().dnsPreByCustom(config.dns);
316321
}
317-
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = dnsPrefetcher.getConcurrentHashMap();
318-
byte[] dnscache = StringUtils.toByteArray(concurrentHashMap);
319-
320-
recorder.set(cacheKey, dnscache);
322+
if (dnsPrefetcher != null) {
323+
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = dnsPrefetcher.getConcurrentHashMap();
324+
byte[] dnscache = StringUtils.toByteArray(concurrentHashMap);
325+
if (dnscache == null)
326+
return;
327+
recorder.set(cacheKey, dnscache);
328+
}
321329
}
322330

323331
/**

library/src/main/java/com/qiniu/android/storage/persistent/DnsCacheFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.qiniu.android.storage.persistent;
22

3+
import com.qiniu.android.http.custom.DnsCacheKey;
34
import com.qiniu.android.storage.Recorder;
45

56
import java.io.File;
@@ -105,7 +106,10 @@ public String getFileName() {
105106
long cachetime = 0;
106107
for (int i = 1; i < fs.length; i++) {
107108
String key = fs[i].getName();
108-
long time = Long.parseLong(key.split(":")[0]);
109+
DnsCacheKey cacheKey = DnsCacheKey.toCacheKey(key);
110+
if(cacheKey==null)
111+
return null;
112+
long time = Long.parseLong(cacheKey.getCurrentTime());
109113
if (time > cachetime) {
110114
del(fileName);
111115
cachetime = time;

0 commit comments

Comments
 (0)