aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorChris Banes <chrisbanes@google.com>2014-02-12 12:39:48 +0000
committerChris Banes <chrisbanes@google.com>2014-02-12 12:39:48 +0000
commit535fde45ab0d43c3843083113fb87c106549775f (patch)
treea93ce5aec7e5f528a10f881b5726d4267606e4f0 /common
parente8362a5065acc3de05444a237cdd04deb0593eee (diff)
downloadandroid-535fde45ab0d43c3843083113fb87c106549775f.tar.gz
Fix possible infinity loop in ag/417350
ag/417350 is a cherry pick of the merged CL ag/416106 which is why this is in klp-dev. I will cherry pick this into klp-docs after it has been merged. Change-Id: Ifcf1fc901acd73ad9ccfef789b73cd5a62a6302c
Diffstat (limited to 'common')
-rw-r--r--common/src/java/com/example/android/common/dummydata/Cheeses.java3
1 files changed, 3 insertions, 0 deletions
diff --git a/common/src/java/com/example/android/common/dummydata/Cheeses.java b/common/src/java/com/example/android/common/dummydata/Cheeses.java
index 220d66a7..783735ce 100644
--- a/common/src/java/com/example/android/common/dummydata/Cheeses.java
+++ b/common/src/java/com/example/android/common/dummydata/Cheeses.java
@@ -174,6 +174,9 @@ public class Cheeses {
Random random = new Random();
HashSet<String> items = new HashSet<String>();
+ // Make sure that don't infinity loop
+ count = Math.min(count, CHEESES.length);
+
while (items.size() < count) {
items.add(CHEESES[random.nextInt(CHEESES.length)]);
}