brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.84k stars 2.33k forks source link

`org.chromium.components.search_engines.TemplateUrl.c()` crashing when selecting SE under `Recently visited` #40705

Open kjozwiak opened 2 months ago

kjozwiak commented 2 months ago

Description

I'm not 100% what is causing the crash but looks like it happens when you attempt to visit more than three different search engines that support Opensearch. You'll notice that only three are appearing under Recently visited. Once you start selecting a SE from Recently visited, you'll notice that the fourth SE is not appearing but sometimes is selected even though you selected something different from the list. For example, selecting yahoo.com but getting you.com even though you.com is not on the list. Eventually you'll run to the following crash which is pretty easy to reproduce.

The above was found as a follow up to https://github.com/brave/brave-core/pull/23659.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.chromium.components.search_engines.TemplateUrl.c()' on a null object reference
    at IL.h(chromium-MonochromePublic64.aab-canary-427103724:18)
    at IL.onClick(chromium-MonochromePublic64.aab-canary-427103724:29)
    at android.view.View.performClick(View.java:8028)
    at android.view.View.performClickInternal(View.java:8005)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:31229)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loopOnce(Looper.java:232)
    at android.os.Looper.loop(Looper.java:317)
    at android.app.ActivityThread.main(ActivityThread.java:8705)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)

Steps to reproduce

At this point, just start picking random SE from both Recently visited and the normal SE. You'll eventually see that if you pick yahoo.com, amazon.com or mojeek.com, you'll sometimes get you.com but it never appears in the list. Eventually Brave will crash.

Actual result

https://github.com/user-attachments/assets/06808a31-a172-4f61-b30f-387370a51a2a

Expected result

Brave shouldn't be crashing when users are switching between SE under Recently visited.

Reproduces how often

Easily reproduced

Brave version

Brave | 1.71.37 Chromium: 128.0.6613.85 (Official Build) canary (64-bit)
--- | ---
Revision | 015c4b27b636aa9d293a3452368e81e3dee6241f
OS | Android 15; Build/AP31.240617.015; 35; REL

Device

Channel information

Reproducibility

Miscellaneous information

No response

kjozwiak commented 2 months ago

Some more info re: the above. I believe this happens when you visit more than three Opensearch websites. Seems like we're only listing three and once more start getting added (but not visible), you're going to run into issues. Another example:

https://github.com/user-attachments/assets/038e158b-5c98-4b54-8e14-0864b77828bb

deeppandya commented 4 weeks ago

i went through the details. and it's an issue in the release channel as well. basically based on the chromium changes, if you have more than 3 OpenSearch options which you haven't selected into search engines, at a time it would only show 3 options and as soon as you select one, it would start showing different options from the list. https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/search_engines/android/java/src/org/chromium/chrome/browser/search_engines/settings/SearchEngineAdapter.java;l=61?q=SearchEngineA&ss=chromium