marunjar / anewjkuapp

GNU General Public License v3.0
16 stars 4 forks source link

ParserException on iCal import #141

Open fsteff opened 4 years ago

fsteff commented 4 years ago

Today I found out that the calendar was not updated properly, so I started debugging... Device: Xiaomi Mi9T Pro OS: Android 10 (MiUi 11) App Version: PlayStore as well as Github master branch

I should probably add that I got an update to android 10 yesterday. (Might be related, but I somehow don't believe this is the case)

net.fortuna.ical4j.data.ParserException: Error at line 1:Expected [VCALENDAR], read [VCALENDAR\nPRODID] at org.voidsink.anewjkuapp.kusss.KusssHandler.loadIcal(KusssHandler.java:482)

While looking for an error I found one suspicious line: KusssHandler.java:380 return data.toString().replace("\r\n", "\\n").getBytes(charset); (I don't get why \\nis inserted instead of \n) However, replacing the\\n with a \ndoes cause a lot of other problems, such as

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String net.fortuna.ical4j.model.property.Description.getValue()' on a null object reference
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.importCalendar(ImportCalendarWorker.java:200)

This makes me think that the additional \ is on purpose - but why does it cause problems just now?

marunjar commented 4 years ago

This is a general problem and not an android 10 specific one.

The replacement of \r\n was a workaround for an older version of ical4j that was not very tolerant with unexpected line separators. The first backslash ist for escaping the second one, so in ical there is a '\n' instead of a newline, that worked.

I tried to read ical without changing response (42b5ac2) and it looks like this works with the current ical4j/kusss version. So i'll publish a version with the fix in the next days.

fsteff commented 4 years ago

Hm, seems there is still a problem, this version does not work for me. Looks like the \\n thing caused fields to be initialized with empty strings (or something like that), now these fields are null. (version https://github.com/marunjar/anewjkuapp/commit/aa20b11faf2318b714674ee7645df37cc73830f9)

E/ImportCalendarWorker: import calendar failed
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String net.fortuna.ical4j.model.property.Description.getValue()' on a null object reference
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.importCalendar(ImportCalendarWorker.java:200)
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.doWork(ImportCalendarWorker.java:100)
        at androidx.work.Worker$1.run(Worker.java:85)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
I/WM-WorkerWrapper: Worker result FAILURE for Work [ id=ecec0bb3-b520-43c4-b59b-84674a3ca430, tags={ org.voidsink.anewjkuapp.worker.ImportCalendarWorker, UPDATE_CAL_LVA } ]
D/skia: --- Failed to create image decoder with message 'unimplemented'
I/WM-WorkerWrapper: Work [ id=f70c4342-3ef2-46ca-9268-86692906b483, tags={ org.voidsink.anewjkuapp.worker.ImportCalendarWorker, UPDATE_CAL_EXAM } ] was cancelled
    java.util.concurrent.CancellationException: Task was cancelled.
        at androidx.work.impl.utils.futures.AbstractFuture.cancellationExceptionWithCause(AbstractFuture.java:1184)
        at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:514)
        at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
        at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:284)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
E/ImportCalendarWorker: import calendar failed
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String net.fortuna.ical4j.model.property.Location.getValue()' on a null object reference
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.getContentValuesFromEvent(ImportCalendarWorker.java:511)
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.importCalendar(ImportCalendarWorker.java:402)
        at org.voidsink.anewjkuapp.worker.ImportCalendarWorker.doWork(ImportCalendarWorker.java:102)
        at androidx.work.Worker$1.run(Worker.java:85)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
fsteff commented 4 years ago

I've started an attempt to fix this with https://github.com/fsteff/anewjkuapp/commit/e5a2b4c700f1841e2d741df465da3eaabbc980a9, but loading exams somehow does not result in any exams being displayed.

marunjar commented 4 years ago

I think i remember.

There were problems with some event fields with multiple line values confusing the parser a little.

Can you provide me (marunjar@aon.at) an anonymized ics file from kusss for debugging? Looks like there's some bad content in there.

Some info for escaping and multile lines can be found here https://github.com/ical4j/ical4j/blob/develop/src/main/java/net/fortuna/ical4j/util/Strings.java or in https://tools.ietf.org/html/rfc5545

marunjar commented 4 years ago

Thanks for data. There are some events in the ics file that have no DESCRIPTION set but i'm expecting that.

I hope i have time to fix this soon.

marunjar commented 4 years ago

@fsteff can you give https://github.com/marunjar/anewjkuapp/tree/ical_fix a try?

fsteff commented 4 years ago

Seems to work fine 👍

However, I noticed one little bug/glitch: my next exam is out of the default timeframe of the exams view, so this view is empty - but there is no button to show later exams (in the android calendar it works perfectly fine)

fsteff commented 4 years ago

One little question: is there a way to force a re-load of the ical if there has been a successful import shortly before (for debugging purposes)? Sometimes I have to uninstall the app in order to archive that...

marunjar commented 4 years ago

re-load should happen if you press refresh on the timetable screen. maybe this happens a little bit delayed because of work manager, but events are loaded again.