From 2a67de4059775466071da52c07b18627c51c677c Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Mon, 31 Aug 2009 09:48:37 -0400 Subject: Check for null tabs before acquiring the parent tab. This prevents a NPE when the current tab is null. This is very rare but can still possibly happen. --- src/com/android/browser/TabControl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index efef303..037a757 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -766,7 +766,7 @@ class TabControl { if (getTabCount() == 0) return; // free the least frequently used background tab - Tab t = getLeastUsedTab(getCurrentTab().getParentTab()); + Tab t = getLeastUsedTab(getCurrentTab()); if (t != null) { Log.w(LOGTAG, "Free a tab in the browser"); freeTab(t); @@ -785,9 +785,10 @@ class TabControl { System.gc(); } - private Tab getLeastUsedTab(Tab currentParent) { - // Don't do anything if we only have 1 tab. - if (getTabCount() == 1) { + private Tab getLeastUsedTab(Tab current) { + // Don't do anything if we only have 1 tab or if the current tab is + // null. + if (getTabCount() == 1 || current == null) { return null; } @@ -802,11 +803,12 @@ class TabControl { do { t = mTabQueue.get(i++); } while (i < queueSize - && ((t != null && t.mMainView == null) || t == currentParent)); + && ((t != null && t.mMainView == null) + || t == current.mParentTab)); // Don't do anything if the last remaining tab is the current one or if // the last tab has been freed already. - if (t == getCurrentTab() || t.mMainView == null) { + if (t == current || t.mMainView == null) { return null; } -- cgit v1.1