Skip to content

Commit 4fe25f6

Browse files
author
Tsu Chiang Chuang
committed
fix NPE in race condition.
Change-Id: Ic1df67f8a5379ff1cd804fb55e143f078e369ccf
1 parent a8c57bf commit 4fe25f6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import com.android.bandwidthtest.NetworkState.StateTransitionDirection;
4545
import com.android.internal.util.AsyncChannel;
4646

47+
import junit.framework.Assert;
48+
4749
import java.io.IOException;
4850
import java.net.UnknownHostException;
4951
import java.util.List;
@@ -453,6 +455,11 @@ public boolean waitForNetworkState(int networkType, State expectedState, long ti
453455
} catch (InterruptedException e) {
454456
e.printStackTrace();
455457
}
458+
if (mNetworkInfo == null) {
459+
Log.v(LOG_TAG, "Do not have networkInfo! Force fetch of network info.");
460+
mNetworkInfo = mCM.getActiveNetworkInfo();
461+
Assert.assertNotNull(mNetworkInfo);
462+
}
456463
if ((mNetworkInfo.getType() != networkType) ||
457464
(mNetworkInfo.getState() != expectedState)) {
458465
Log.v(LOG_TAG, "network state for " + mNetworkInfo.getType() +

0 commit comments

Comments
 (0)