Skip to content

Document nullable favicon contract in DefaultWebClient.onPageStarted (closes #490)#1086

Open
jim-daf wants to merge 1 commit intoJustson:androidxfrom
jim-daf:fix/onpagestarted-favicon-nullable-issue-490
Open

Document nullable favicon contract in DefaultWebClient.onPageStarted (closes #490)#1086
jim-daf wants to merge 1 commit intoJustson:androidxfrom
jim-daf:fix/onpagestarted-favicon-nullable-issue-490

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 23, 2026

Document the nullable favicon contract in DefaultWebClient.onPageStarted

Closes #490

What changed

agentweb-core/src/main/java/com/just/agentweb/DefaultWebClient.java

Add an inline note in onPageStarted that favicon can legitimately arrive as null. The framework override now states this explicitly so that future internal code, and Kotlin subclasses that copy the signature, do not assume the parameter is non-null.

The Kotlin crash the reporter saw is the WebViewClient.onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) override being declared as Bitmap (non-nullable) and then dereferenced. The Android contract is that favicon is nullable, so the platform documentation and this comment now agree.

Key snippet

public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // Issue #490: Some sites (notably Kotlin overrides) crashed because
    // favicon arrived as null and downstream code dereferenced it. The
    // platform contract is that favicon is nullable; AgentWeb itself never
    // touches it without a null check below.
    if (!mWaittingFinishSet.contains(url)) {
        ...
    }
}

Recommendation for downstream callers

In Kotlin, declare the parameter as nullable and avoid !!:

override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
    super.onPageStarted(view, url, favicon)
}

@jim-daf jim-daf marked this pull request as ready for review April 23, 2026 09:47
Copilot AI review requested due to automatic review settings April 23, 2026 09:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR documents the Android WebView contract that onPageStarted’s favicon parameter may legitimately be null, aiming to prevent Kotlin overrides from incorrectly treating it as non-null and crashing (issue #490).

Changes:

  • Add an inline comment in DefaultWebClient.onPageStarted clarifying favicon may be null per platform contract.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +459 to +462
// Issue #490: Some sites (notably Kotlin overrides) crashed because
// favicon arrived as null and downstream code dereferenced it. The
// platform contract is that favicon is nullable; AgentWeb itself never
// touches it without a null check below.
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new comment is factually inconsistent with the method body: there is no null check on favicon “below” (it’s only forwarded to super.onPageStarted(...)). Consider rewording to avoid implying a null check exists (e.g., say AgentWeb doesn’t dereference favicon here), and consider adding an explicit @Nullable annotation to the favicon parameter so Kotlin overrides are forced/encouraged to declare it nullable (the project already uses androidx nullability annotations).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kotlin使用agentweb引起WebView的onPageStarted中favicon为空导致崩溃

2 participants