Use try-with-resources and multi-catch exceptions in IMMS.

This CL applies new Java 7 language features try-with-resources
and multi-catch exceptions to InputMethodManagerService.

Basically this is a compile-time replacement hence there should
be neither behavior difference nor performance impact.

Bug: 22285167
Change-Id: I971bd12b63649802859410ee6a91351b1261f055
This commit is contained in:
Yohei Yukawa
2015-08-11 13:29:24 -07:00
parent b03bf67276
commit 5894b434aa

View File

@@ -2923,10 +2923,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
if (DEBUG) {
Slog.d(TAG, "Found an input method " + p);
}
} catch (XmlPullParserException e) {
Slog.w(TAG, "Unable to load input method " + compName, e);
} catch (IOException e) {
} catch (XmlPullParserException | IOException e) {
Slog.w(TAG, "Unable to load input method " + compName, e);
}
}
@@ -3635,9 +3632,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
if (allSubtypes == null || subtypesFile == null) return;
allSubtypes.clear();
FileInputStream fis = null;
try {
fis = subtypesFile.openRead();
try (final FileInputStream fis = subtypesFile.openRead()) {
final XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, StandardCharsets.UTF_8.name());
int type = parser.getEventType();
@@ -3692,23 +3687,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
tempSubtypesArray.add(subtype);
}
}
} catch (XmlPullParserException e) {
Slog.w(TAG, "Error reading subtypes: " + e);
} catch (XmlPullParserException | IOException | NumberFormatException e) {
Slog.w(TAG, "Error reading subtypes", e);
return;
} catch (java.io.IOException e) {
Slog.w(TAG, "Error reading subtypes: " + e);
return;
} catch (NumberFormatException e) {
Slog.w(TAG, "Error reading subtypes: " + e);
return;
} finally {
if (fis != null) {
try {
fis.close();
} catch (java.io.IOException e1) {
Slog.w(TAG, "Failed to close.");
}
}
}
}
}