From 30921031653799519a7acab46f5c7da2f81c25d5 Mon Sep 17 00:00:00 2001 From: Dimitris Dafnis <68849116+jim-daf@users.noreply.github.com> Date: Tue, 21 Apr 2026 21:55:20 +0200 Subject: [PATCH] fix(WebViewClientDelegate): supply non-null favicon placeholder to delegates (#490) Resolves #490 WebView delivers onPageStarted with a null favicon during early page-start. WebViewClientDelegate forwards that value straight to the user's delegate. Kotlin delegates whose signature declares the favicon parameter as a non-null Bitmap (the default in Kotlin source unless explicitly Bitmap?) crash at the synthetic Intrinsics.checkParameterIsNotNull bytecode: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter favicon This change substitutes a 1x1 transparent ARGB_8888 placeholder bitmap for a null favicon before forwarding to the delegate. The placeholder is lazily created and cached, so there is no cost on the common path where the platform supplies a real bitmap. Delegates that declared the parameter as Bitmap? still work, just with a non-null value. --- .../just/agentweb/WebViewClientDelegate.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/agentweb-core/src/main/java/com/just/agentweb/WebViewClientDelegate.java b/agentweb-core/src/main/java/com/just/agentweb/WebViewClientDelegate.java index 2b2ed1dd..34526aea 100644 --- a/agentweb-core/src/main/java/com/just/agentweb/WebViewClientDelegate.java +++ b/agentweb-core/src/main/java/com/just/agentweb/WebViewClientDelegate.java @@ -68,13 +68,43 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request return super.shouldOverrideUrlLoading(view, request); } + /** + * One-pixel transparent placeholder used in place of a null favicon when + * forwarding {@link #onPageStarted(WebView, String, Bitmap)} to a delegate + * whose Kotlin signature declares favicon as a non-null {@code Bitmap}. + * Allocated lazily so there is no cost when the platform supplies a real + * favicon. See issue #490. + */ + private static volatile Bitmap sFaviconPlaceholder; + + private static Bitmap faviconPlaceholder() { + Bitmap placeholder = sFaviconPlaceholder; + if (placeholder == null) { + synchronized (WebViewClientDelegate.class) { + placeholder = sFaviconPlaceholder; + if (placeholder == null) { + placeholder = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); + sFaviconPlaceholder = placeholder; + } + } + } + return placeholder; + } + @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { + // Issue #490: WebView may deliver a null favicon at page-start. Kotlin + // delegates whose signature declares favicon as non-null Bitmap will + // crash at the synthetic Intrinsics.checkParameterIsNotNull check. + // Substitute a tiny transparent placeholder so non-null Kotlin + // signatures keep working; nullable signatures see no observable + // change beyond receiving a non-null bitmap. + Bitmap safeFavicon = favicon != null ? favicon : faviconPlaceholder(); if (mDelegate != null) { - mDelegate.onPageStarted(view, url, favicon); + mDelegate.onPageStarted(view, url, safeFavicon); return; } - super.onPageStarted(view, url, favicon); + super.onPageStarted(view, url, safeFavicon); } @Override