From da5790de786ff2bc07928d5975c7e4e2709cf41b Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 24 Mar 2017 17:22:33 +0900 Subject: Fix double-checked locking in InputMethodSubtype No functional change. Fixes: 35737935 Test: run cts test and confirmed all tests passed cts-tradefed run singleCommand cts-dev -m CtsInputMethodTestCases Change-Id: I44e5e91b6462c3c7d023f50365b30da9cf98c509 --- .../view/inputmethod/InputMethodSubtype.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java index 44309a7b68c2..28c2d016f6db 100644 --- a/core/java/android/view/inputmethod/InputMethodSubtype.java +++ b/core/java/android/view/inputmethod/InputMethodSubtype.java @@ -520,27 +520,27 @@ public final class InputMethodSubtype implements Parcelable { } private HashMap getExtraValueHashMap() { - if (mExtraValueHashMapCache == null) { - synchronized(this) { - if (mExtraValueHashMapCache == null) { - mExtraValueHashMapCache = new HashMap(); - final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); - final int N = pairs.length; - for (int i = 0; i < N; ++i) { - final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); - if (pair.length == 1) { - mExtraValueHashMapCache.put(pair[0], null); - } else if (pair.length > 1) { - if (pair.length > 2) { - Slog.w(TAG, "ExtraValue has two or more '='s"); - } - mExtraValueHashMapCache.put(pair[0], pair[1]); - } + synchronized (this) { + HashMap extraValueMap = mExtraValueHashMapCache; + if (extraValueMap != null) { + return extraValueMap; + } + extraValueMap = new HashMap<>(); + final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); + for (int i = 0; i < pairs.length; ++i) { + final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); + if (pair.length == 1) { + extraValueMap.put(pair[0], null); + } else if (pair.length > 1) { + if (pair.length > 2) { + Slog.w(TAG, "ExtraValue has two or more '='s"); } + extraValueMap.put(pair[0], pair[1]); } } + mExtraValueHashMapCache = extraValueMap; + return extraValueMap; } - return mExtraValueHashMapCache; } /** -- cgit v1.2.3-59-g8ed1b