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
[expo-calendar][android] Fixed calendar crashes with java.lang.NumberFormatException #12724
Conversation
On android, Expo Calendar throws a fatal error if the device used has another app for calendar management such as the one mentioned in issue expo#1853, or in my case "Nine - Email & Calendar" if it is used to sync certain calendars (e.g outlook). To error thrown is: `Fatal Exception: java.lang.NumberFormatException: For input string: ""` To avoid this error I added a check to make sure the string is a parsable integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution 💪
Please add a changelog note to the expo-calendar
package and change the regex expression into the try-catch block.
if(!constant.isEmpty() && constant.matches("-?\\d+")){ | ||
array.add(reminderStringMatchingConstant(Integer.parseInt(constant))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be better to put Integer.parseInt
into the try-catch block.
Pushed the requested changes. |
packages/expo-calendar/android/src/main/java/expo/modules/calendar/CalendarModule.java
Outdated
Show resolved
Hide resolved
packages/expo-calendar/android/src/main/java/expo/modules/calendar/CalendarModule.java
Outdated
Show resolved
Hide resolved
packages/expo-calendar/android/src/main/java/expo/modules/calendar/CalendarModule.java
Outdated
Show resolved
Hide resolved
packages/expo-calendar/android/src/main/java/expo/modules/calendar/CalendarModule.java
Outdated
Show resolved
Hide resolved
…ndar/CalendarModule.java Co-authored-by: Łukasz Kosmaty <kosmatylukasz@gmail.com>
…ndar/CalendarModule.java Co-authored-by: Łukasz Kosmaty <kosmatylukasz@gmail.com>
…ndar/CalendarModule.java Co-authored-by: Łukasz Kosmaty <kosmatylukasz@gmail.com>
…ndar/CalendarModule.java Co-authored-by: Łukasz Kosmaty <kosmatylukasz@gmail.com>
…FormatException (#12724) # Why On android, Expo Calendar throws a fatal error if the device used has another app installed for calendar management such as the one mentioned in issue #1853, or in my case "Nine - Email & Calendar" if it is used to sync certain calendars (e.g outlook). The error thrown is: `Fatal Exception: java.lang.NumberFormatException: For input string: ""` Steps to reproduce error: 1. Install an app that uses Expo Calendar and retrieves the calendars on the device, for example by calling `ExpoCalendar.getCalendarsAsync()` 2. Verify calendars are fetched an app does not crash 3. Create an Outlook account 4. Install "Nine - Email & Calendar" App and sync the calendar with the new Outlook account 5. Open the app that uses Expo Calendar Result: App will crash # How To avoid this fatal error I added a check to make sure the string is a parsable integer. # Test Plan 1. Install an app that uses Expo Calendar and retrieves the calendars on the device, for example by calling `ExpoCalendar.getCalendarsAsync()` 2. Verify calendars are fetched an app does not crash 3. Create an Outlook account 4. Install "Nine - Email & Calendar" App and sync the calendar with the new Outlook account 5. Open the app that uses Expo Calendar Result: App will not crash this time
Why
On android, Expo Calendar throws a fatal error if the device used has another app installed for calendar management such as the one mentioned in issue #1853, or in my case "Nine - Email & Calendar" if it is used to sync certain calendars (e.g outlook).
The error thrown is:
Fatal Exception: java.lang.NumberFormatException: For input string: ""
Steps to reproduce error:
ExpoCalendar.getCalendarsAsync()
Result: App will crash
How
To avoid this fatal error I added a check to make sure the string is a parsable integer.
Test Plan
ExpoCalendar.getCalendarsAsync()
Result: App will not crash this time
Checklist
expo build
(eg: updated@expo/xdl
).expo prebuild
& EAS Build (eg: updated a module plugin).