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

[expo-calendar][android] Fixed calendar crashes with java.lang.NumberFormatException #12724

Merged
merged 9 commits into from Apr 26, 2021

Conversation

ibraude
Copy link
Contributor

@ibraude ibraude commented Apr 25, 2021

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

Checklist

  • Documentation is up to date to reflect these changes (eg: https://docs.expo.io and README.md).
  • This diff will work correctly for expo build (eg: updated @expo/xdl).
  • This diff will work correctly for expo prebuild & EAS Build (eg: updated a module plugin).

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.
@ibraude ibraude requested a review from lukmccall as a code owner April 25, 2021 18:12
@ibraude ibraude changed the title Fix Issue #1853 [android][calendar] Fixed Issue #1853 Apr 25, 2021
Copy link
Contributor

@lukmccall lukmccall left a 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.

Comment on lines 932 to 934
if(!constant.isEmpty() && constant.matches("-?\\d+")){
array.add(reminderStringMatchingConstant(Integer.parseInt(constant)));
}
Copy link
Contributor

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.

@ibraude
Copy link
Contributor Author

ibraude commented Apr 26, 2021

Pushed the requested changes.
Thanks!

ibraude and others added 4 commits April 26, 2021 15:33
…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>
@lukmccall lukmccall changed the title [android][calendar] Fixed Issue #1853 [expo-calendar][android] Fixed calendar crashes with java.lang.NumberFormatException Apr 26, 2021
@lukmccall lukmccall merged commit a27ff2a into expo:master Apr 26, 2021
tsapeta pushed a commit that referenced this pull request Apr 26, 2021
…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
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.

None yet

2 participants