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

Crash when loading "Deleted files" #3212

Closed
Kiaatix opened this issue Nov 1, 2018 · 5 comments
Closed

Crash when loading "Deleted files" #3212

Kiaatix opened this issue Nov 1, 2018 · 5 comments

Comments

@Kiaatix
Copy link

Kiaatix commented Nov 1, 2018

Nextcloud app version:
3.3.1
Nextcloud server version:
14.0.3

The app crashes when there are many files with equal names in the trashbin.

Stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.nextcloud.client, PID: 10317
    java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.TimSort.mergeHi(TimSort.java:895)
        at java.util.TimSort.mergeAt(TimSort.java:512)
        at java.util.TimSort.mergeCollapse(TimSort.java:437)
        at java.util.TimSort.sort(TimSort.java:241)
        at java.util.Arrays.sort(Arrays.java:1523)
        at java.util.Collections.sort(Collections.java:238)
        at com.owncloud.android.utils.FileSortOrderByName.sortTrashbinFiles(FileSortOrderByName.java:76)
        at com.owncloud.android.ui.adapter.TrashbinListAdapter.setTrashbinFiles(TrashbinListAdapter.java:89)
        at com.owncloud.android.ui.trashbin.TrashbinActivity.showTrashbinFolder(TrashbinActivity.java:256)
        at com.owncloud.android.ui.trashbin.TrashbinPresenter$1.onSuccess(TrashbinPresenter.java:72)
        at com.owncloud.android.ui.trashbin.RemoteTrashbinRepository$ReadRemoteTrashbinFolderTask.onPostExecute(RemoteTrashbinRepository.java:211)
        at com.owncloud.android.ui.trashbin.RemoteTrashbinRepository$ReadRemoteTrashbinFolderTask.onPostExecute(RemoteTrashbinRepository.java:175)
        at android.os.AsyncTask.finish(AsyncTask.java:660)
        at android.os.AsyncTask.-wrap1(AsyncTask.java)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

I think it's because AlphanumComparator().compare(o1, o2); always returns -1 for identical filenames (at least for files with a '.' in their name) in com.owncloud.android.utils.FileSortOrderByName:84.

Workaround:
if (o1.getFileName().equals(o2.getFileName())) return 0; before FileSortOrderByName.java:84

@nextcloud-android-bot
Copy link
Collaborator

GitMate.io thinks possibly related issues are #2574 (crash on file delete), #2515 (Crash at files loading), #2281 ([Deleted]), #117 (Crash when last account is deleted), and #1695 (Crash when trying to upload many files).

@tobiasKaminsky
Copy link
Member

Can you give some sample names where this occurs?
We have multiple test cases for sorting, and I assumed that handling "." in it is working.

Do yo really have two files with the exact same file name? Otherwise your workaround would not apply?

@AndyScherzinger
Copy link
Member

We also have a fix which has been contributed a couple of days ago regarding sorting which might already fix this.
Could you test the dev version available on f-droid?

@tobiasKaminsky
Copy link
Member

I tested this with latest master:

  • created 1.txt & deleted it
  • created 1.txt & deleted it
  • open up deleted files
  • see two times 1.txt, but no crash

@Kiaatix
Copy link
Author

Kiaatix commented Nov 1, 2018

OK the dev-version works for me, so the issue can be closed.

To reproduce the error is quite difficult. It just happened in my private account with thousands of files in the trash-bin. The filename where it eventually crashed was 2b(Kd=0).png
There were 4-5 files with that name.

I was able to track down that it was because third_parties.daveKoeller.AlphanumComparator#compare(java.lang.String, java.lang.String) always returns -1 if both inputs have this value, eventually stating that
element1 < element2 and element2 < element1, which is not possible in a total order.

Technically, most sorting-algorithms should still terminate correctly; it should just result in unnecessary swaps.
I'm not really familiar with Java and how it detects "Comparison method violates its general contract!" when sorting. Maybe the detection depends on the position of the files in the list, or it's size (more recursions/iterations of the sorting algorithm)...

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

No branches or pull requests

4 participants