@@ -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 /**
0 commit comments