Skip to content

Commit 920c01a

Browse files
authored
Merge pull request #385 from JemyCheung/master
exception
2 parents 2d875e5 + 02d6228 commit 920c01a

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#Changelog
22

3+
# 7.6.2
4+
* 修复序列化异常
5+
* 更正打点日志字段
6+
37
# 7.6.1
48
* 修复上传区域错误
59
* 更正打点日志字段

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ https://github.com/qiniudemo/qiniu-lab-android
2424
| 7.0.7 | Android 2.2+ | android-async-http 1.4.8 |
2525

2626
### 注意
27-
* 推荐使用最新版:7.6.1,7.6.1使用okhttp4.2.2
27+
* 推荐使用最新版:7.6.2,7.6.2使用okhttp4.2.2
2828
* 7.4.3是在7.5.2版本上降低okhttp版本,其他功能不变
2929
* 从 7.3.13 开始,不在强制依赖 `happy-dns-android`,默认不再提供 `httpDns`,可以调用 `Configuration.Builder#dns(com.qiniu.android.http.Dns)`方法设置外部 `Dns`,自定义 `Dns` 要求实现 `com.qiniu.android.http.Dns` 接口。
3030
* 从7.5.0开始增加了DNS预取和缓存策略,减少dns解析错误

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.6.1";
5+
public static final String VERSION = "7.6.2";
66

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ public static void startPrefetchDns(String token, Configuration config) {
415415
* @return
416416
*/
417417
public static boolean recoverDnsCache(byte[] data) {
418-
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = (ConcurrentHashMap<String, List<InetAddress>>) StringUtils.toObject(data);
418+
ConcurrentHashMap<String, List<InetAddress>> concurrentHashMap = null;
419+
try {
420+
concurrentHashMap = (ConcurrentHashMap<String, List<InetAddress>>) StringUtils.toObject(data);
421+
}catch (Exception e){
422+
return true;
423+
}
419424
if (concurrentHashMap == null) {
420425
return true;
421426
}

library/src/main/java/com/qiniu/android/utils/StringUtils.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,20 @@ public static String strip(String s) {
147147
*/
148148
public static byte[] toByteArray(Object obj) {
149149
byte[] bytes = null;
150-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
151150
try {
152-
ObjectOutputStream oos = new ObjectOutputStream(bos);
153-
oos.writeObject(obj);
154-
oos.flush();
155-
bytes = bos.toByteArray();
156-
oos.close();
157-
bos.close();
151+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
152+
try {
153+
ObjectOutputStream oos = new ObjectOutputStream(bos);
154+
try {
155+
oos.writeObject(obj);
156+
oos.flush();
157+
bytes = bos.toByteArray();
158+
} finally {
159+
oos.close();
160+
}
161+
} finally {
162+
bos.close();
163+
}
158164
} catch (IOException ex) {
159165
ex.printStackTrace();
160166
}
@@ -171,14 +177,17 @@ public static Object toObject(byte[] bytes) {
171177
Object obj = null;
172178
try {
173179
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
174-
ObjectInputStream ois = new ObjectInputStream(bis);
175-
obj = ois.readObject();
176-
ois.close();
177-
bis.close();
178-
} catch (IOException ex) {
179-
ex.printStackTrace();
180-
} catch (ClassNotFoundException ex) {
181-
ex.printStackTrace();
180+
try {
181+
ObjectInputStream ois = new ObjectInputStream(bis);
182+
obj = ois.readObject();
183+
ois.close();
184+
} catch (Exception ex) {
185+
ex.printStackTrace();
186+
} finally {
187+
bis.close();
188+
}
189+
} catch (Exception e) {
190+
e.printStackTrace();
182191
}
183192
return obj;
184193
}

0 commit comments

Comments
 (0)