Skip to content

Commit fb59fbf

Browse files
Romain GuyAndroid Code Review
authored andcommitted
Merge "Add better error handling for savePicture and restorePicture"
2 parents e99c012 + dad8634 commit fb59fbf

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

core/java/android/webkit/WebView.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,18 +1182,29 @@ public boolean savePicture(Bundle b, File dest) {
11821182
return false;
11831183
}
11841184
final Picture p = capturePicture();
1185+
1186+
FileOutputStream out = null;
1187+
boolean success = false;
11851188
try {
1186-
final FileOutputStream out = new FileOutputStream(dest);
1189+
out = new FileOutputStream(dest);
11871190
p.writeToStream(out);
1188-
out.close();
1191+
success = true;
11891192
} catch (FileNotFoundException e){
11901193
e.printStackTrace();
11911194
} catch (IOException e) {
11921195
e.printStackTrace();
11931196
} catch (RuntimeException e) {
11941197
e.printStackTrace();
1198+
} finally {
1199+
if (out != null) {
1200+
try {
1201+
out.close();
1202+
} catch (Throwable t) {
1203+
}
1204+
}
11951205
}
1196-
if (dest.length() > 0) {
1206+
1207+
if (success && dest.length() > 0) {
11971208
b.putInt("scrollX", mScrollX);
11981209
b.putInt("scrollY", mScrollY);
11991210
b.putFloat("scale", mActualScale);
@@ -1217,16 +1228,23 @@ public boolean restorePicture(Bundle b, File src) {
12171228
}
12181229
if (src.exists()) {
12191230
Picture p = null;
1231+
FileInputStream in = null;
12201232
try {
1221-
final FileInputStream in = new FileInputStream(src);
1233+
in = new FileInputStream(src);
12221234
p = Picture.createFromStream(in);
1223-
in.close();
12241235
} catch (FileNotFoundException e){
12251236
e.printStackTrace();
12261237
} catch (RuntimeException e) {
12271238
e.printStackTrace();
12281239
} catch (IOException e) {
12291240
e.printStackTrace();
1241+
} finally {
1242+
if (in != null) {
1243+
try {
1244+
in.close();
1245+
} catch (Throwable t) {
1246+
}
1247+
}
12301248
}
12311249
if (p != null) {
12321250
int sx = b.getInt("scrollX", 0);

0 commit comments

Comments
 (0)