Open Bug 1908134 Opened 11 months ago Updated 4 months ago

Fix null pointer bug in `PrefWithoutDefault`

Categories

(GeckoView :: General, defect, P2)

All
Android
defect

Tracking

(Not tracked)

People

(Reporter: olivia, Unassigned, Mentored)

References

(Blocks 2 open bugs)

Details

(Keywords: good-first-bug, Whiteboard: [geckoview:2024H2?][geckoview:introduction][gv-h1-2025?][fxdroid][geckoview])

PrefWithoutDefault has a bug that will produce a crash if the value is attempted to get while still null. get().

An example of the stack trace may be found here. Unused patch that reproduces this failure and failing test examples.

[task 2024-03-11T14:51:25.409Z] 14:51:25 INFO - 03-11 14:51:24.809 E/GeckoSessionTestRule( 3449): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference

This might be a seperate bug or a part of this one, please split if the scope is too much:

Additionally, paraphrasing :jonalmeida, noted that:
There might also be a related or same root cause bug around RuntimeSettings#runWithAllPrefs.

  • PrefWithoutDefault calls commit using super.commit.
  • super.commit() then calls addToBundle around here
  • The PrefWithoutDefault addToBundle is unused and likely was the intended addToBundle to use.
  • So calling RuntimeSettings#runWithAllPrefs might cause a crash.
See Also: → 1888979
Summary: Fix bug in `PrefWithoutDefault` → Fix null pointer bug in `PrefWithoutDefault`
Blocks: 1908182

Olivia, can you add a bit more info?

Mentor: ohall, bugzeeeeee
Severity: -- → S2
Flags: needinfo?(ohall)
Priority: -- → P2

Sure, for anyone interested in taking this as a good first bug, I'd recommend:

  • Ideally, PrefWithoutDefault should not have public @Nullable T get() as an option.
    • Recommend first jumping to the testing section and creating a test that reproduces the issue.
    • To fix this, a sensible default could be checking to see if Gecko has a value. (If Gecko does have a value, then this is the acting pref anyway!)
    • When ready to work on the fix:
      • A new message could be sent, such as GeckoView:GetGeckoPref or GeckoView:GetGeckoPrefs in GeckoViewStartup.sys.mjs
      • It could be patterened off of GeckoView:SetDefaultPrefs here. However, instead of setting prefs, we should get the values for use.
    • Then, on the Java side, around here We could call EventDispatcher.getInstance().dispatch("GeckoView:GetGeckoPref", data); and get a value.
    • I'm suspicious it might also be possible to get null or undefined from this API. In that case, if Gecko returns null, then consider just sending a sensible primative type result back, e.g., "", false, or 0.

For testing:

  • Recommend looking at existing PrefWithoutDefault usage and basing tests off of that.
  • A known way to reproduce the original issue is found here. Unused patch that reproduces this failure and failing test examples. This pref no longer uses PrefWithoutDefault, but a new test could be patterened off of it. I'd recommmend getting a reproducing failure first, before attempting changes.

This would also set the stage for 1888979 as part of that bug would additionally need a clear way to GeckoView:GetGeckoPref.

Flags: needinfo?(ohall)
Keywords: good-first-bug
Whiteboard: [geckoview:2024H2?][geckoview:introduction]
Blocks: 1909024
No longer blocks: 1909024
See Also: → 1909024

I can take this one.

Thanks for your interest! I assigned the bug to you. Please feel free to needinfo me for questions or for a review.

Assignee: nobody → alex.kattathra.johnson

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: alex.kattathra.johnson → nobody
Whiteboard: [geckoview:2024H2?][geckoview:introduction] → [geckoview:2024H2?][geckoview:introduction][gv-h1-2025?]

Good Afternoon,
I'm wondering if I can take on this bug as my first bugfix?

Thanks!

(In reply to JCesium from comment #6)

Good Afternoon,
I'm wondering if I can take on this bug as my first bugfix?

Thanks!

Cancel that actually. I don't have the right setup to really debug and test this appropriately.

Whiteboard: [geckoview:2024H2?][geckoview:introduction][gv-h1-2025?] → [geckoview:2024H2?][geckoview:introduction][gv-h1-2025?][fxdroid][geckoview]
Blocks: 1888979
You need to log in before you can comment on or make changes to this bug.