Android: AutoUpload - IllegalArgumentException: Comparison method violates its general contract!

Created on 3 Nov 2017  路  11Comments  路  Source: nextcloud/android

Actual behaviour

  • AutoUpload view crashes

Expected behaviour

  • AutoUpload view shouldn't crash

Steps to reproduce

  1. Open the AutoUpload view in the drawer

Environment data

Android version: 6.0.1

Device model: OnePlus 2

Stock or customized system: Stock Oxygen OS 3.6.1

Nextcloud app version: 2.0.1

Nextcloud server version: 12.0.3

Issue reference #198

Logs

Nextcloud logcat (adb logcat)

FATAL EXCEPTION: main
Process: com.nextcloud.client, PID: 9426
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nextcloud.client/com.owncloud.android.ui.activity.SyncedFoldersActivity}: java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
    at android.app.ActivityThread.access$900(ActivityThread.java:155)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:152)
    at android.app.ActivityThread.main(ActivityThread.java:5497)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.TimSort.mergeHi(TimSort.java:882)
    at java.util.TimSort.mergeAt(TimSort.java:499)
    at java.util.TimSort.mergeForceCollapse(TimSort.java:440)
    at java.util.TimSort.sort(TimSort.java:219)
    at java.util.Arrays.sort(Arrays.java:1998)
    at java.util.Collections.sort(Collections.java:1900)
    at com.owncloud.android.ui.activity.SyncedFoldersActivity.sortSyncedFolderItems(SyncedFoldersActivity.java:274)
    at com.owncloud.android.ui.activity.SyncedFoldersActivity.load(SyncedFoldersActivity.java:223)
    at com.owncloud.android.ui.activity.SyncedFoldersActivity.setupContent(SyncedFoldersActivity.java:197)
    at com.owncloud.android.ui.activity.SyncedFoldersActivity.onCreate(SyncedFoldersActivity.java:150)
    at android.app.Activity.performCreate(Activity.java:6289)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
    ... 9 more
bug AutoUpload pr exists

Most helpful comment

Hi,
I built a local release with this easy fix and it worked fine.

Thx

All 11 comments

We tried to solve this. As far as I know the cause is that during sorting the state of objects change. This is not allowed in TimSort.
So we must "freeze" the state/infos of the objects (uploading/pending, upload date, ...)

I took a look at the previous bug (#198) but I can't find how to do the same thing here.
Any hints?

@tobiasKaminsky : can you label with AutoUpload too ?

@tobiasKaminsky see stack trace SyncedFoldersActivity this is related to the auto upload screen not the uploads screen, so the state is actually frozen (!) so this one should be easily fixable if the root cause in the sort implementation has been found...

@ymage labelled it auto upload :)

My guess, is that the f1 == + f2 == and any of the other checks that only look at 1 of the two items cause the problem since a flip of the items would lead to the same result...

@ymage please ignore #198 since that solution didn't fix the issue... :(

I believe we basically violate:

  • anticommutation : x.compareTo(y) is the opposite sign of y.compareTo(x)

let's assume both folder's name equals PRIORITIZED_FOLDER

  • f1 compared to f2 --> -1
  • f2 compared to f1 --> -1

This is due to the fact that there is no
if (PRIORITIZED_FOLDER.equals(f1.getFolderName()) && PRIORITIZED_FOLDER.equals(f2.getFolderName()))

So this should be very easy to fix. 馃帀

Plus while looking at (my) code there is also another part that is kind of missing which is if folder names are equal then we should still sort by type... 馃槙 But for an easy fix I think it should just be the line mentioned above.

Hi,
I built a local release with this easy fix and it worked fine.

Thx

Thanks for the feedback @ymage! Fancy a PR? 馃榾

@ymage I reviewed the PR, just awaiting a second review by one of the other maintainers :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tobiasKaminsky picture tobiasKaminsky  路  3Comments

JSoko picture JSoko  路  3Comments

AndyScherzinger picture AndyScherzinger  路  3Comments

tobiasKaminsky picture tobiasKaminsky  路  3Comments

JSoko picture JSoko  路  3Comments