Fix ICUServiceThreadTest flakiness
Sometimes getVisibleIDs() method returns a null reference which might happend
because of inaccurate concurrent access. This CL attempts to fix this
ICUServiceThreadTest flakiness.
Bug: 129457872
Test: cts-tradefed run commandAndExit cts-dev -m CtsIcuTestCases -t android.icu.dev.test.util.ICUServiceTest
Change-Id: Ia802465eca7a4fbc25abb11b090abfb4b2fef451
diff --git a/android_icu4j/src/main/java/android/icu/impl/ICUService.java b/android_icu4j/src/main/java/android/icu/impl/ICUService.java
index 850da1a..aa79df4 100644
--- a/android_icu4j/src/main/java/android/icu/impl/ICUService.java
+++ b/android_icu4j/src/main/java/android/icu/impl/ICUService.java
@@ -597,13 +597,15 @@
Factory f = lIter.previous();
f.updateVisibleIDs(mutableMap);
}
- this.idcache = Collections.unmodifiableMap(mutableMap);
+ Map<String, Factory> result = Collections.unmodifiableMap(mutableMap);
+ this.idcache = result;
+ return result;
} finally {
factoryLock.releaseRead();
}
}
+ return idcache;
}
- return idcache;
}
private Map<String, Factory> idcache;
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java
index 4db16b3..afdbfa9 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUService.java
@@ -592,13 +592,15 @@
Factory f = lIter.previous();
f.updateVisibleIDs(mutableMap);
}
- this.idcache = Collections.unmodifiableMap(mutableMap);
+ Map<String, Factory> result = Collections.unmodifiableMap(mutableMap);
+ this.idcache = result;
+ return result;
} finally {
factoryLock.releaseRead();
}
}
+ return idcache;
}
- return idcache;
}
private Map<String, Factory> idcache;