From 68dc380d62b29b4b6733bc1b20e44b8931c1d341 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Tue, 30 Nov 2010 10:38:34 -0800 Subject: [PATCH] Don't throw exception on moveToPosition in CachedCursor * Just return false Bug: 3240290 Change-Id: I808ca88c7897c573d19c2c2c92b179b4106a6dd3 --- .../android/email/provider/ContentCache.java | 17 ++++++----------- .../email/provider/ContentCacheTests.java | 8 +------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/com/android/email/provider/ContentCache.java b/src/com/android/email/provider/ContentCache.java index 6a89d5b96..011887750 100644 --- a/src/com/android/email/provider/ContentCache.java +++ b/src/com/android/email/provider/ContentCache.java @@ -262,7 +262,9 @@ public final class ContentCache extends LinkedHashMap { /** * The cached cursor is simply a CursorWrapper whose underlying cursor contains zero or one * rows. We handle simple movement (moveToFirst(), moveToNext(), etc.), and override close() - * to keep the underlying cursor alive (unless it's no longer cached due to an invalidation) + * to keep the underlying cursor alive (unless it's no longer cached due to an invalidation). + * Multiple CachedCursor's can use the same underlying cursor, so we override the various + * moveX methods such that each CachedCursor can have its own position information */ public static final class CachedCursor extends CursorWrapper { // The cursor we're wrapping @@ -310,14 +312,11 @@ public final class ContentCache extends LinkedHashMap { } /** - * We'll be happy to move to position 0 or -1; others are illegal + * We'll be happy to move to position 0 or -1 */ @Override public boolean moveToPosition(int pos) { - if (pos > 0) { - throw new IllegalArgumentException(); - } - if (pos >= getCount()) { + if (pos >= getCount() || pos < -1) { return false; } mPosition = pos; @@ -336,11 +335,7 @@ public final class ContentCache extends LinkedHashMap { @Override public boolean moveToPrevious() { - if (mPosition == 0) { - mPosition--; - return true; - } - return false; + return moveToPosition(mPosition - 1); } @Override diff --git a/tests/src/com/android/email/provider/ContentCacheTests.java b/tests/src/com/android/email/provider/ContentCacheTests.java index 2360246d2..7d2c4e2bd 100644 --- a/tests/src/com/android/email/provider/ContentCacheTests.java +++ b/tests/src/com/android/email/provider/ContentCacheTests.java @@ -168,13 +168,7 @@ public class ContentCacheTests extends ProviderTestCase2 { assertEquals(0, cursor.getPosition()); cursor.moveToPosition(0); assertEquals(0, cursor.getPosition()); - // And something that should - try { - cursor.moveToPosition(1); - fail("Shouldn't be able to move to position > 0"); - } catch (IllegalArgumentException e) { - // Correct - } + assertFalse(cursor.moveToPosition(1)); cursor.close(); // We've closed the cached cursor; make sure