Due to an error in Android 4.3, my application crashes when trying to load certain web pages in webview
The stack trace looks like this:
09-16 14:16:48.221: E/AndroidRuntime(22487): FATAL EXCEPTION: WebViewCoreThread 09-16 14:16:48.221: E/AndroidRuntime(22487): java.lang.StringIndexOutOfBoundsException: length=0; index=-1 09-16 14:16:48.221: E/AndroidRuntime(22487): at java.lang.AbstractStringBuilder.indexAndLength(AbstractStringBuilder.java:212) 09-16 14:16:48.221: E/AndroidRuntime(22487): at java.lang.AbstractStringBuilder.charAt(AbstractStringBuilder.java:206) 09-16 14:16:48.221: E/AndroidRuntime(22487): at java.lang.StringBuffer.charAt(StringBuffer.java:346) 09-16 14:16:48.221: E/AndroidRuntime(22487): at com.android.org.bouncycastle.asn1.x509.X509NameTokenizer.nextToken(X509NameTokenizer.java:78) 09-16 14:16:48.221: E/AndroidRuntime(22487): at com.android.org.bouncycastle.asn1.x509.X509Name.<init>(X509Name.java:719) 09-16 14:16:48.221: E/AndroidRuntime(22487): at com.android.org.bouncycastle.asn1.x509.X509Name.<init>(X509Name.java:655) 09-16 14:16:48.221: E/AndroidRuntime(22487): at com.android.org.bouncycastle.asn1.x509.X509Name.<init>(X509Name.java:593) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.net.http.SslCertificate$DName.<init>(SslCertificate.java:379) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.net.http.SslCertificate.<init>(SslCertificate.java:189) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.net.http.SslCertificate.<init>(SslCertificate.java:178) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.webkit.BrowserFrame.setCertificate(BrowserFrame.java:1206) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.os.Handler.dispatchMessage(Handler.java:99) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.os.Looper.loop(Looper.java:137) 09-16 14:16:48.221: E/AndroidRuntime(22487): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:814) 09-16 14:16:48.221: E/AndroidRuntime(22487): at java.lang.Thread.run(Thread.java:841)
In my webview, I have onReceivedSslError and the onReceivedError methods are overridden, but none of them can catch this exception.
try{ webview.postUrl(url, EncodingUtils.getBytes(data, "BASE64")); } catch(Exception e){ System.out.println("Caught the exception!"); }
the surrounding call to postUrl using the try / catch block (as indicated above) also throws no exception.
Is there a way to catch this exception so that I can display a meaningful error message instead of allowing the application to crash?
source share