Android - NPE in BrowserFrame
I get this exception triggered by users occasionally that I cannot reproduce. Since it's issued from looper I suppose it is result of Handler-type callback. I found similar bug on Google code but putting the solution into code didn't solve it. The problem is at this line of code in BrowserFrame:
WebAddress uri = new WebAddress(
mCallbackProxy.getBackForwardList().getCur开发者_StackOverflowrentItem()
.getUrl());
Which throws this Exception because I suppose mCallbackProxy is null
java.lang.NullPointerException
at android.webkit.BrowserFrame.handleMessage(BrowserFrame.java:348)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:471)
at java.lang.Thread.run(Thread.java:1060)
And the questions are - will this forclose the app? And how do I work around this bug?
So I invested some time into investigating this problem. The error comes from this code in BrowserFrame:
case FRAME_COMPLETED: {
if (mSettings.getSavePassword() && hasPasswordField()) {
if (WebView.DEBUG) {
Assert.assertNotNull(mCallbackProxy.getBackForwardList()
.getCurrentItem());
}
WebAddress uri = new WebAddress(
mCallbackProxy.getBackForwardList().getCurrentItem()
.getUrl());
String schemePlusHost = uri.mScheme + uri.mHost;
String[] up = mDatabase.getUsernamePassword(schemePlusHost);
if (up != null && up[0] != null) {
setUsernamePassword(up[0], up[1]);
}
}
CacheManager.trimCacheIfNeeded();
break;
}
Specifically from this line
WebAddress uri = new WebAddress(
mCallbackProxy.getBackForwardList().getCurrentItem()
The only place where mCallbackProxy is set is in BrowserFrame
constructor which gets null for CallbackProxy
parameter for whatever reason. Since I cannot try/catch this code (It is called from Looper) the only way I can deal with this error is to set WebSettings#setSavePassword(false)
when I initialize WebView
in my code. In which case IF
statement fails and offending code is never executed
精彩评论