Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid NumberFormatException on String > Integer.MAX_INT #17505

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

mikehardy
Copy link
Member

Purpose / Description

In the settings -> backups section you can paste whatever you want (or type whatever you want) number-wise into the prefs

If you put something too large in there (like, 9999999999) then you'll crash

This uses an internal function already special built for this, to not crash

Fixes

https://ankidroid.org/acra/app/1/bug/249351/report/5d5ad546-4725-4cf3-b93f-b601b26f4cde

java.lang.NumberFormatException: For input string: "9638527410"
	at java.lang.Integer.parseInt(Integer.java:797)
	at java.lang.Integer.parseInt(Integer.java:915)
	at com.ichi2.preferences.NumberRangePreferenceCompat$NumberRangeDialogFragmentCompat.onDialogClosed(SourceFile:35)
	at androidx.preference.PreferenceDialogFragmentCompat.onDismiss(SourceFile:12)
	at androidx.fragment.app.DialogFragment$3.onDismiss(SourceFile:15)
	at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1480)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:224)
	at android.os.Looper.loop(Looper.java:318)
	at android.app.ActivityThread.main(ActivityThread.java:8777)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

Approach

Realize we already had a safe String-to-int function, expose it for use, use it

How Has This Been Tested?

Reproduced the crash locally, doesn't crash after
Reproduced all other number dialog and increment dialog behavior after, seems to work

Learning (optional, can help others)

Users are monkeys and they'll input anything (but it's okay, I'm a monkey too)

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Nov 26, 2024
@BrayanDSO BrayanDSO added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Nov 26, 2024
@BrayanDSO BrayanDSO added this pull request to the merge queue Nov 26, 2024
Merged via the queue into ankidroid:main with commit 0fe5e9b Nov 26, 2024
12 checks passed
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Nov 26, 2024
@github-actions github-actions bot modified the milestones: 2.19.3 release, 2.20 Release Nov 26, 2024
@mikehardy mikehardy deleted the fix-numberformatexception branch November 26, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants