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

getTimeZone() causes NPE #229

Open
rfc2822 opened this issue Apr 18, 2018 · 18 comments
Open

getTimeZone() causes NPE #229

rfc2822 opened this issue Apr 18, 2018 · 18 comments
Assignees
Projects

Comments

@rfc2822
Copy link
Contributor

rfc2822 commented Apr 18, 2018

ical4j 2.2.20, Android

When calling getTimeZone() on a registry created by TimeZoneRegistryFactory.getInstance().createRegistry(), it sometimes generates a NullPointerException:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.Calendar.setTimeZone(java.util.TimeZone)' on a null object reference
      at java.text.DateFormat.setTimeZone(DateFormat.java:690)
      at net.fortuna.ical4j.model.Iso8601.<init>(Iso8601.java:77)
      at net.fortuna.ical4j.model.Date.<init>(Date.java:150)
      at net.fortuna.ical4j.model.DateTime.<init>(DateTime.java:262)
      at net.fortuna.ical4j.util.Dates.getInstance(Dates.java:223)
      at net.fortuna.ical4j.model.component.Observance.getLatestOnset(Observance.java:230)
      at net.fortuna.ical4j.model.TimeZone.getRawOffset(TimeZone.java:180)
      at net.fortuna.ical4j.model.TimeZone.<init>(TimeZone.java:69)
      at net.fortuna.ical4j.data.CalendarBuilder$ContentHandlerImpl.endComponent(CalendarBuilder.java:245)
      at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.parse(CalendarParserImpl.java:444)
      at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.access$900(CalendarParserImpl.java:406)
      at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:208)
      at net.fortuna.ical4j.data.CalendarParserImpl.parseCalendar(CalendarParserImpl.java:115)
      at net.fortuna.ical4j.data.CalendarParserImpl.parseCalendarList(CalendarParserImpl.java:180)
      at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:149)
      at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:198)
      at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:178)
      at net.fortuna.ical4j.data.CalendarBuilder.build(CalendarBuilder.java:165)
      at net.fortuna.ical4j.model.TimeZoneLoader.loadVTimeZone(TimeZoneLoader.java:99)
      at net.fortuna.ical4j.model.TimeZoneRegistryImpl.getTimeZone(TimeZoneRegistryImpl.java:181)
      at at.bitfire.ical4android.AndroidEvent.populateEvent(AndroidEvent.kt:169)

I don't know which time zone causes the problems yet, but I think getTimeZone() should not throw an unchecked exception in any case.

@rfc2822
Copy link
Contributor Author

rfc2822 commented Apr 22, 2018

Same as #219

@rfc2822
Copy link
Contributor Author

rfc2822 commented Apr 25, 2018

I have opened it again because the other issue is about returning null, and this is about a NullPointerException. Unfortunately, I couldn't find the cause yet although this seems to occur quite often.

@rfc2822 rfc2822 reopened this Apr 25, 2018
@noloman
Copy link

noloman commented May 22, 2018

Same thing happening here, with 2.0.0. What's the status of this? Any ideas? workarounds?

@rfc2822
Copy link
Contributor Author

rfc2822 commented May 22, 2018

@noloman Does it happen in Android 8.0.0 only or on other platforms? Meanwhile I assume this is some kind of firmware bug, especially because the NPE happens in java.text.DateFormat.setTimeZone(DateFormat.java:690) and not in ical4j

@noloman
Copy link

noloman commented May 30, 2018

@rfc2822 it only happens (for now on Android 8.0.0) but it only happens when using the library for parsing a DateTime. Is there any known workaround, even if it's modifying the backend? Thanks for the good work guys!

@noloman
Copy link

noloman commented May 30, 2018

BTW this is also happening on other versions of Android, not only 8. Could it maybe not be an Android bug?

@rfc2822
Copy link
Contributor Author

rfc2822 commented Jul 21, 2018

@noloman On which other version have you seen that? We have only seen it with Android 8.0, although we have many users with various versions.

Uninstalling the app and installing it again sometime fixes the problem magically, which is very strange…

For reference, this is our thread: https://forums.bitfire.at/post/9654

@benfortuna benfortuna self-assigned this Jul 25, 2018
@noloman
Copy link

noloman commented Jul 31, 2018

well unfortunately, telling our customers to remove and install the app is really not a suitable solution, as you will understand.
Unfortunately I haven't ever been able to reproduce this issue, neither with the emulator nor with a real device, so I'm out of ideas

@rfc2822
Copy link
Contributor Author

rfc2822 commented Jul 31, 2018

@noloman Same here (not reproducible). At the moment, I think it may be somehow related to an Android cache…

And we tell our customers to re-install, too… just because there's no better solution at the moment. This is why I have mentioned it.

@benfortuna
Copy link
Member

If you have suggestions on how to work around the issue let me know (eg extra error handling)

@noloman
Copy link

noloman commented Aug 3, 2018

well I can give you guys several datetime strings in the ICS that can't be parsed (20180714T193000 for example). If you try to debug with that String -I haven't personally tried THAT string, but I have tried with others- you can dive into the debug until you reach the NPE

@noloman
Copy link

noloman commented Sep 4, 2018

Hi, BTW in which versions, if any, can you guys NOT reproduce this? I was using 2.2.0 and I have upgraded now to 3.0.1, so hopefully this crash won't happen again?

@rfc2822
Copy link
Contributor Author

rfc2822 commented Sep 4, 2018

Unfortunately, upgrading to 3.x is not an option for me, because we have to support Android <7, too (and ical4j 3.x requires JDK 8 libraries, which are only available on Android 7+).

@noloman
Copy link

noloman commented Sep 4, 2018 via email

@rfc2822
Copy link
Contributor Author

rfc2822 commented Sep 4, 2018

What do you mean? I have upgraded and built gradle plus executed the app in an emulator (Oreo) but I didn't have any issue. Is it supposed to crash if it's run in < Oreo?

Yes, or does it work for you in <Oreo emulator? There are many operations which rely on the Java 8 API, which requires Android >= 7. Java 8 bytecode wouldn't be the problem, but the API…

@noloman
Copy link

noloman commented Sep 17, 2018

Indeed @rfc2822 I understood it completely wrong: it is crashing on devices with Android < Nougat, but working on the newer versions

@rfc2822
Copy link
Contributor Author

rfc2822 commented Sep 18, 2018

Theoretically, it should be possible to make a class loader which dynamically injects the required classes for Android < 7…

@benfortuna benfortuna added this to Needs triage in Android via automation Nov 24, 2018
@JorisBodin
Copy link

Hello 👋
Any news on this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Android
  
Needs triage
Development

No branches or pull requests

4 participants