2

I found many duplicate issues related to this title, but none of them were related to my issue since my issue cannot be traced through crashlytics. I keep receiving many different crashes regarding this title.

Check this example (it is happening only on android 4) :

enter image description here

Fatal Exception: java.lang.IllegalArgumentException: Comparison method violates its general contract!
       at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:831)
       at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:449)
       at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:372)
       at java.util.ComparableTimSort.sort(ComparableTimSort.java:178)
       at java.util.ComparableTimSort.sort(ComparableTimSort.java:142)
       at java.util.Arrays.sort(Arrays.java:1970)
       at java.util.Collections.sort(Collections.java:1864)
       at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:6872)
       at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:6837)
       at android.view.ViewGroup.dispatchPopulateAccessibilityEventInternal(ViewGroup.java:2706)
       at android.view.View.dispatchPopulateAccessibilityEvent(View.java:5217)
       at android.view.ViewGroup.dispatchPopulateAccessibilityEventInternal(ViewGroup.java:2712)
       at android.view.View.dispatchPopulateAccessibilityEvent(View.java:5217)
       at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5177)
       at android.view.View.sendAccessibilityEventUnchecked(View.java:5159)
       at android.view.View.sendAccessibilityEventInternal(View.java:5136)
       at android.view.View.sendAccessibilityEvent(View.java:5105)
       at android.view.View.performClick(View.java:4649)
       at android.view.View$PerformClick.run(View.java:19438)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:146)
       at android.app.ActivityThread.main(ActivityThread.java:5602)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
       at dalvik.system.NativeStart.main(NativeStart.java)

I found through research that it happens when comparing/sorting while missing out a certain condition. Meanwhile in my code, i do not use the compare or the sort method mentioned in the documentations/examples.

Any advise is highly appreciated.

JKOU
  • 255
  • 2
  • 14

1 Answers1

2

It seems to be an AOSP's bug as pointed out by @bwt.

The error is part of the framework's API: http://www.docjar.com/html/api/java/util/ComparableTimSort.java.html (line 835)

In this case, something wrong happened in the Android's source code because of the way that you build your layout, specifically how you organized the ViewGroup's elements.

If it only happens on Android 4, one way to fix it is to upgrade your minSdk to at least 5. Another way, is to implement the solution that some people described in the issue tracker link, which could cause your app to loose some accessibility feature. Anther possibility is trying to find a different way to organize your layout that won't crash, but since the logic that causes the crash is embedded in AOSP, this would run out of your control and maybe to count on lucky.

I personally would go to the minSdk upgrade, which according to Google would represent a very low impact to your app due to the number of users in Android 4 today.

  • Will check it out, but i am afraid of trying to override the ViewGroup function which might ruin some already built up code, i may have a lot of children views with top xy the same as others, but the code is already built, and i can not trace it back to what exactly is the problem. I do not want to change a working code without knowing if it had the issue or not in the said layout. – JKOU Apr 08 '19 at 06:49