You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This error happened on my PaperMC server, but I believe it to be a brigadier issue.
Step 1: Make a new com.mojang.brigadier.suggestion.SuggestionsBuilder
Step 2: builder.suggest specific mix of integers and strings
Step 3: builder.buildFuture().join;
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.base/java.util.TimSort.mergeLo(TimSort.java:781) ~[?:?]
at java.base/java.util.TimSort.mergeAt(TimSort.java:518) ~[?:?]
at java.base/java.util.TimSort.mergeCollapse(TimSort.java:448) ~[?:?]
at java.base/java.util.TimSort.sort(TimSort.java:245) ~[?:?]
at java.base/java.util.Arrays.sort(Arrays.java:1308) ~[?:?]
at java.base/java.util.ArrayList.sort(ArrayList.java:1804) ~[?:?]
at com.mojang.brigadier.suggestion.Suggestions.create(Suggestions.java:99) ~[brigadier-1.3.10.jar:?]
at com.mojang.brigadier.suggestion.SuggestionsBuilder.build(SuggestionsBuilder.java:51) ~[brigadier-1.3.10.jar:?]
at com.mojang.brigadier.suggestion.SuggestionsBuilder.buildFuture(SuggestionsBuilder.java:55) ~[brigadier-1.3.10.jar:?]
at net.minecraft.server.network.ServerGamePacketListenerImpl.handleCustomCommandSuggestions0(ServerGamePacketListenerImpl.java:844) ~[paper-1.21.1.jar:1.21.1-DEV-755a775]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleCustomCommandSuggestions$1(ServerGamePacketListenerImpl.java:811) ~[paper-1.21.1.jar:1.21.1-DEV-755a775]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
The issue occurs in Suggestions.create()
finalList<Suggestion> sorted = newArrayList<>(texts);
sorted.sort((a, b) -> a.compareToIgnoreCase(b));
when sorted is a mix of IntegerSuggestion and Suggestion:
The exception is due to transitivity violations in the comparator logic:
Comparator Contract Violations:
Transitivity: If a < b and b < c, then a < c must hold.
In the classes:
IntegerSuggestion objects are compared based on value.
Suggestion objects are compared based on text.
Mixing comparisons between these two types can lead to scenarios where transitivity is violated.
Example Scenario:
Let s1 be a Suggestion with text = "apple".
Let i1 be an IntegerSuggestion with value = 2 (text = "2").
Let i2 be an IntegerSuggestion with value = 3 (text = "3").
Comparisons:
i1.compareToIgnoreCase(i2) compares based on value: 2 < 3 → returns -1 (i1 < i2).
i2.compareToIgnoreCase(s1) compares based on text: "3".compareToIgnoreCase("apple") → positive value (i2 > s1).
Transitivity Violation: From i1 < i2 and i2 > s1, transitivity implies i1 < s1. However, i1.compareToIgnoreCase(s1) compares based on text: "2".compareToIgnoreCase("apple") → positive value (i1 > s1), which contradicts the transitivity requirement.
Here is java code that replicates the issue every time
This error happened on my PaperMC server, but I believe it to be a brigadier issue.
Step 1: Make a new com.mojang.brigadier.suggestion.SuggestionsBuilder
Step 2: builder.suggest specific mix of integers and strings
Step 3: builder.buildFuture().join;
The issue occurs in Suggestions.create()
when sorted is a mix of IntegerSuggestion and Suggestion:
In suggestion:
is used to compare whereas in integer suggestion:
is used to compare them.
The exception is due to transitivity violations in the comparator logic:
Comparator Contract Violations:
Transitivity: If a < b and b < c, then a < c must hold.
In the classes:
IntegerSuggestion objects are compared based on value.
Suggestion objects are compared based on text.
Mixing comparisons between these two types can lead to scenarios where transitivity is violated.
Example Scenario:
Let s1 be a Suggestion with text = "apple".
Let i1 be an IntegerSuggestion with value = 2 (text = "2").
Let i2 be an IntegerSuggestion with value = 3 (text = "3").
Comparisons:
i1.compareToIgnoreCase(i2) compares based on value: 2 < 3 → returns -1 (i1 < i2).
i2.compareToIgnoreCase(s1) compares based on text: "3".compareToIgnoreCase("apple") → positive value (i2 > s1).
Transitivity Violation: From i1 < i2 and i2 > s1, transitivity implies i1 < s1. However, i1.compareToIgnoreCase(s1) compares based on text: "2".compareToIgnoreCase("apple") → positive value (i1 > s1), which contradicts the transitivity requirement.
Here is java code that replicates the issue every time
The text was updated successfully, but these errors were encountered: