fix java.lang.IllegalArgumentException: Comparison method violates its general contract! (#6239)

This commit is contained in:
fo40225 2024-11-15 09:26:50 +08:00 committed by GitHub
parent a5fe6e21bc
commit 008ac38ebc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,20 +14,23 @@ public class ReadChunks {
points.add(new Point(chunk.getOffset(), chunk, true)); points.add(new Point(chunk.getOffset(), chunk, true));
points.add(new Point(chunk.getOffset() + chunk.getSize(), chunk, false)); points.add(new Point(chunk.getOffset() + chunk.getSize(), chunk, false));
} }
Collections.sort(points, new Comparator<Point>() { Collections.sort(points, new Comparator<Point>() {
@Override @Override
public int compare(Point a, Point b) { public int compare(Point a, Point b) {
int x = (int) (a.x - b.x); int xComparison = Long.compare(a.x, b.x);
if (a.x != b.x) { if (xComparison != 0) {
return (int) (a.x - b.x); return xComparison;
} }
if (a.ts != b.ts) {
return (int) (a.ts - b.ts); // If x values are equal, compare ts
int tsComparison = Long.compare(a.ts, b.ts);
if (tsComparison != 0) {
return tsComparison;
} }
if (!a.isStart) {
return -1; // If both x and ts are equal, prioritize start points
} return Boolean.compare(b.isStart, a.isStart); // b.isStart first to prioritize starts
return 1;
} }
}); });